Java_ActionListener_Test
来源:互联网 发布:网络云音乐 编辑:程序博客网 时间:2024/04/29 17:13
- import java.awt.*;
- import java.awt.event.*;
- import javax.swing.*;
- public class ActionTest
- {
- public static void main(String[] args)
- {
- ActionFrame aFrame = new ActionFrame();
- aFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- aFrame.setVisible(true);
- }
- }
- class ActionFrame extends JFrame
- {
- public ActionFrame()
- {
- Toolkit t = Toolkit.getDefaultToolkit();
- Dimension d = t.getScreenSize();
- int screenWidth = (int)d.getWidth();
- int screenHeight = (int)d.getHeight();
- setSize(screenWidth/2,screenHeight/2);
- setLocation(screenWidth/4,screenHeight/4);
- setTitle("ActionTest_InnerClass");
- ActionPanel aPanel = new ActionPanel();
- Container content = getContentPane();
- content.add(aPanel);
- }
- }
- class ActionPanel extends JPanel
- {
- public ActionPanel()
- {
- makeButton("YellowButton",Color.YELLOW);
- makeButton("BlueButton",Color.BLUE);
- makeButton("GreenButton",Color.GREEN);
- }
- public void makeButton(String buttonName,final Color c)
- {
- JButton aButton = new JButton(buttonName);
- aButton.addActionListener(
- new ActionListener()
- {
- public void actionPerformed(ActionEvent e)
- {
- setBackground(c);
- }
- }
- );
- add(aButton);
- }
- }
代码中的黑体部分就是对编译错误的修改,Color c必须是final类型的。当时也在想String buttonName前面也没有final修饰,为什么不出编译错误呢?是因为Java中的String类是final类型的。所以说String类是不能被继承的!!!
- Java_ActionListener_Test
- Building a Web Site for Dummies
- QVector QList QLinkedList
- Beginning J2ME: From Novice to Professional, Third Edition
- Intellij IDEA的web部署问题(端口8080被占用)
- 面试相关-非技术问题
- Java_ActionListener_Test
- Hacking GMail (ExtremeTech)
- 如何設定 Windows Live Writer(繁中) 來編寫 CSDN 部落格
- QT中的常用数据结构
- 数字幻方,有兴趣的来
- IBM Data Warehousing: With IBM Business Intelligence Tools
- Architecture of Reliable Web Applications Software
- 常见的几个Qt编程问题的处理
- 十个故事