日期:2014-05-20  浏览次数:20715 次

我创建 了两个窗体 ,为什么 关闭了其中一个窗体后,整个程序就关闭了 ???

public   class   Main   {

        /**
          *   @param   args   the   command   line   arguments
          */
        public   static   void   main(String[]   args)   {
                //   TODO   code   application   logic   here
            new   NewJFrame(   ).setVisible(true);
          new   NewJFrame(   ).setVisible(true);      
           
        }


上面的代码是程序一运行就创建   了两个窗体   ,关闭了其中一个窗体后,整个程序就关闭了  

怎么才能   关闭了其中一个窗体后,整个程序都可以继续运行


------解决方案--------------------
你程序中是不是有这句
setDefaultCloseOperation(EXIT_ON_CLOSE);
找了注了试试
------解决方案--------------------
重写类WindowAdapter类中的windowClosing方法就行了

写法:
class MyWindow extends WindowAdapter
{
public void windowClosing(WindowEvent wevent)
{
dispose();
}
}