xuejianhui

导航

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()这个方法, 是尽可能去重绘组件。

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

posted on 2012-11-21 10:27  xuejianhui  阅读(4096)  评论(0编辑  收藏  举报