Window事件_java

import java.awt.Color;
import java.awt.Frame;
import java.awt.event.WindowAdapter;

public class MyWindowClose {
	public static void main(String[] args) {
		new MyWindowFrame("关闭窗口");
	}
}
class MyWindowFrame extends Frame{
	public MyWindowFrame(String s) {
		// TODO Auto-generated constructor stub
		super(s);
		setLayout(null);//布局格式
		setBackground(Color.DARK_GRAY);//背景颜色
		setBounds(300,300,300,300);//宽高位置
		setVisible(true);//是否可见
		this.addWindowListener(new WindowAdapter() {
				public void windowClosing(java.awt.event.WindowEvent e) {
					setVisible(false);//设置不可见
					System.exit(0);//退出程序
				};
			}
		);
	}
}