最近在写一个文本编辑器,里面用到了新建文档,我用的是重新创建一个文本编辑器类的实例 如:
 public class editor extends JFrame implements ....{   public void ActionPerform(ActionEvent e){
     if(e.getActioncommand()=="新建")
              new editor();
    }}但是当我关闭其中一个窗口时,整个程序都结束了,也就是全部是一个进程,请问高手怎么样把他们独立,想互不干扰呢。

解决方案 »

  1.   

    new editor().setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
      

  2.   

    退出   System.exit(0);
      

  3.   

    System.exit(0) 是你关闭了所有程序了。。 应该用CrazyGou的方法来关你的JFrame,而不是用exit(0)
      

  4.   

    setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);然后给Frame加上自己的事件:
            addWindowListener(new WindowAdapter() {
                public void windowClosing(WindowEvent e) {
                   //TODO 处理代码            }
    }适用 dispose来关闭,应该在主窗口关闭时才使用 System.exit(0)