按钮监听
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
public class TestActionEvent {
public static void main(String[] args) {
//按下按钮触发一些事件。
Frame frame = new Frame();
Button button = new Button("button");
button.setBounds(11,11,11,11);
//因为addActionListener()需要一个ActionListener所以我们要构造一个ActionListener。
MyActionListener myActionListener = new MyActionListener();
button.addActionListener(myActionListener);
WindowsClose(frame);//窗口关闭事件
frame.add(button);
frame.setVisible(true);
frame.setBounds(222,222,222,222);
}
//窗口关闭事件
private static void WindowsClose(Frame frame){
frame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {