import java.awt.*;
import java.awt.event.*;
public class TestActionEvent {
public static void main(String args[]) {
Frame f = new Frame("Test");
Button b = new Button("Press Me!");
Monitor bh = new Monitor();
b.addActionListener(bh);
f.add(b,BorderLayout.CENTER);
f.pack();
f.setVisible(true);
}
}
class Monitor implements ActionListener {
public void actionPerformed(ActionEvent e) {
System.out.println("a button has been pressed");
}
}
3 回答
yanrun
TA贡献317条经验 获得超240个赞
第6行已经创建了Frame类的对象f了啊,再说这样调用也不是调用静态方法啊,如果是静态方法应该这么调用Frame.setVisible();Frame.pack();
添加回答
举报
0/150
提交
取消