package GUI;
import java.awt.Button;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
public class StudyAction {
private Frame f;
private Button but;
StudyAction(){
init();
}
private void init() {
f=new Frame("Window ------by Von");
f.setBounds(300, 100, 600, 500);
f.setLayout(new FlowLayout());
but=new Button("Click me to close");
f.add(but);
dealwithEvent();
f.setVisible(true);
}
private void dealwithEvent() {
f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e){ //区分大小写,WindowClosing则不可
System.exit(0);
}
});
but.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
});
}
public static void main(String[] args) {
new StudyAction();
}
}
JAVA之GUI编程ACTION事件,布布扣,bubuko.com
原文地址:http://www.cnblogs.com/vonk/p/3850231.html