事件监听
package GUI.lesson02;
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();
frame.setVisible(true);
Button button = new Button("sss");
MyActionLister myActionLister = new MyActionLister();
button.addActionListener(myActionLister);
frame.add(button,BorderLayout.CENTER);
frame.pack();
windowClose(frame);
}
private static void windowClose(Frame frame){
frame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}
}
//事件监听
class MyActionLister implements ActionListener{
@Override
public void actionPerformed(ActionEvent e) {
System.out.println("句子");
}
}