Swing中启动多个面板时,关闭其中一个其他的面板也都关闭了,如何做到Exit的只是当前想要关闭的面板。

解决方案 »

  1.   

    给Button一个关闭事件:ActionListener ExitActionListener = new ActionListener() {        public void actionPerformed(ActionEvent e) {
                System.out.println("MenuItem[" + e.getActionCommand() + "]");
                System.exit(0);
            }
        };或者窗口关闭按钮 setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
      

  2.   

    System.exit(0);
    这是程序无异常退出。
    结束了总程序的运行。你的意思是打开一个窗口,关闭上一个窗口是吗?
    用对象.dispose();
    这就搞定了!