想给它加个计数器按一次就输出A button was pressed i times
我的代码,修改一下啊
package gui;
import java.awt.*;
import java.awt.event.*;
public class TestActionListener {
public static void main(String[] args) {
Frame f = new Frame("aaa");
Button b = new Button("Press Me");
Monitor bn = new Monitor();
b.addActionListener(bn);
f.add(b);
f.pack();
f.setVisible(true);
}
}
class Monitor implements ActionListener {
public void actionPerformed(ActionEvent e) {
System.out.println("A button was pressed ");
}
} |
|