Java关闭窗口和刷新


// 关闭窗口 写法1:
    public Structure() {
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                closeWindows();
            }
        });
    }

    private void closeWindows() {
        this.dispose();
    }

// 关闭窗口 写法2:
    public Structure() {
        WindowListener wndCloser = new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        };

        addWindowListener(wndCloser);
    }

// 设置控件边界及其标题:
    jPanel.setBorder(new TitledBorder("jPanel"));

// 设置控件颜色:
    jButton1.setBackground(Color.YELLOW);

################################################################################

<刷新>:
    在swing编程时, 建议用validate()这个方法,能及时查验组件;
    在awt  编程时, 建议用repaint()这个方法, 是尽可能去重绘组件。

################################################################################


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM