1 创建一个窗口及关闭
public class AWTMainWindow extends Frame implements WindowListener {
private AWTMainWindow(){
this.setTitle("AWTWindow");
this.setSize(800, 480);
// 关闭窗口方法之一 - 实现WindowListener
this.addWindowListener(this);
// 关闭窗口方法之二 - 使用WindowAdapter
// this.addWindowListener(new WindowAdapter(){
// public void windowClosing(WindowEvent e){
// System.exit(0);
// }
// });
}
/**
* @param args
*/
public static void main(String[] args) {
AWTMainWindow win = new AWTMainWindow();
win.setVisible(true);
}
public void windowOpened(WindowEvent e) {
// TODO Auto-generated method stub
}
public void windowClosing(WindowEvent e) {
System.out.println(e);
this.dispose();
}
public void windowClosed(WindowEvent e) {
System.out.println(e);
System.exit(0);
}
public void windowIconified(WindowEvent e) {
// TODO Auto-generated method stub
}
public void windowDeiconified(WindowEvent e) {
// TODO Auto-generated method stub
}
public void windowActivated(WindowEvent e) {
// TODO Auto-generated method stub
}
public void windowDeactivated(WindowEvent e) {
// TODO Auto-generated method stub
}
}
2