窗口监听


//窗口监听
public class TestWindow {
    public static void main(String[] args) {
        new WondowFrame();
    }
}

class WondowFrame extends Frame {
    public WondowFrame(){
        setBackground(Color.red);
        setBounds(100,100,100,100);
        setVisible(true);
        this.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                setVisible(false);//隐藏窗口,通过按钮,隐藏当前窗口
                System.exit(0);//
            }
        });
    }
}