// 继承 JFrame 并重写 setVisible 方法
new JFrame("abcde") {
public void setVisible(boolean b) {
if (b) {
this.setSize(320, 100);
System.out.println("我要显示了!!!");
}
super.setVisible(b);
}
}.setVisible(true);
JButton btn = new JButton("按钮");
// ActioinListener 就是一个接口
ActionListener listener = new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.out.println("点击了" + e.getActionCommand());
}
};
btn.addActionListener(listener);
#4
谁说不能继承啊?
public class Test
{
public static void main(String[] args)
{
Thread t = new Thread(){
public void run()
{
System.out.println("Hello, World");
}
};
t.start();
}
}
#5
谁说不能继承啊?
public class Test
{
public static void main(String[] args)
{
Thread t = new Thread(){
public void run()
{
System.out.println("Hello, World");
}
};
t.start();
}
}