在网上搜了一下都说dispose()可以关闭窗口,可是发现dispose()只能把窗口隐藏掉,我后面的程序照样还在运行中。
请问什么方法可以关闭当前的JFrame窗口并停止运行程序?(不能使用System.exit())。

解决方案 »

  1.   

    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);???
      

  2.   

    对Jframe了解的很少,不知道用setVisiable是不是可以阿?帮你顶一下!!
      

  3.   

    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)
      

  4.   

    dispose()方法释放由此 Window、其子组件及其拥有的所有子组件所使用的所有本机屏幕资源。即这些 Component 的资源将被破坏,它们使用的所有内存都将返回到操作系统,并将它们标记为不可显示。
    这个不光是不显示。也会释放资源啊。。怎么会不管用呢,我们一直都这么用啊
      

  5.   

    说明下:
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)是手动关闭框架时的响应动作,用于包含多哥框架集中,关了其中一个框架程序不会退出! 其实,这个方法也是隐藏框架.隐藏框架就可以了,你非要关做什么?退一步dispose()方法够用了.
      

  6.   

    public void setDefaultCloseOperation(int operation) {
    if (operation != DO_NOTHING_ON_CLOSE &&
        operation != HIDE_ON_CLOSE &&
        operation != DISPOSE_ON_CLOSE &&
        operation != EXIT_ON_CLOSE) {
                throw new IllegalArgumentException("defaultCloseOperation must be one of: DO_NOTHING_ON_CLOSE, HIDE_ON_CLOSE, DISPOSE_ON_CLOSE, or EXIT_ON_CLOSE");
    }
            if (this.defaultCloseOperation != operation) {
                if (operation == EXIT_ON_CLOSE) {
                    SecurityManager security = System.getSecurityManager();
                    if (security != null) {
                        security.checkExit(0);
                    }
                }
                int oldValue = this.defaultCloseOperation;
                this.defaultCloseOperation = operation;
                firePropertyChange("defaultCloseOperation", oldValue, operation);
    }
        }
    /////////////////////////////////////////////////////////
    public void checkExit(int status) {
    checkPermission(new RuntimePermission("exitVM"));
        }
    /////////////////////////////////////////////////////////
    operation == EXIT_ON_CLOSE 时,直接都退出 虚拟机了 难道还只是隐藏?
      

  7.   

    设置JFrame.EXIT_ON_CLOSE只会在点窗口右上角的“X”时会有System.exit()的效果,对于在窗口中的按钮没有任何作用啊!而且即使是那个“X”也不是我想要的效果~~~~~~~~~~~~~~~
      

  8.   

    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    就这样
      

  9.   

    f.addWindowListener(new WindowAdapter()
    {
    public void windowClosing(WindowEvent e)
    {
    System.exit(0);
    }
    });
    加这监听,当点激"X"时就会关闭窗口
    也可以用new WindowAdapter()
    {
    public void windowClosing(WindowEvent e)
    {
    System.exit(0);
    }
    }
    另写一个事件触发关闭窗口
      

  10.   

    button.addActionListener(new WindowAdapter()
    {
    public void windowClosing(WindowEvent e)
    {
    System.exit(0);
    }
    });
    点激button关闭窗口
      

  11.   

    jframe.dispose() 方法,会关闭该窗口,与点击右上角的X的功能一样。如果之前对jframe注册过窗口事件,那么也会触发其监听器。