JFrame jf1=new JFrame();
jf1.dispose();

解决方案 »

  1.   

    安装WindowAdapter接口。响应windowClosing 事件。如果是子窗口的话,先的到子窗口的引用,如果这个窗口以后还要用,就用setVisible(false)让它暂时消失。如果以后不用了, 就用dispose()清除掉。
      

  2.   

    JFrame jf2=new JFrame();jf2.addWindowListener(new WindowAdapter(){
          public void windowClosing(WindowEvent e){
            jf2.dispose();//关闭窗口的
          }
        });
      

  3.   

    你好zllzmcDCR:
        可以使用setVisible(false);方法解决你的问题。
      

  4.   

    setVisible(false)  方法不释放该frame占用的内存,是吗?
      

  5.   

    setVisible(false)  方法不释放该frame占用的内存,是吗?我想应该是的。dispose()
    就是释放掉资源了
    API:
    Releases all of the native screen resources used by this Window, its subcomponents, and all of its owned children. That is, the resources for these Components will be destroyed, any memory they consume will be returned to the OS, and they will be ed as undisplayable.
      

  6.   

    还有个问题,我的子frame是在父亲frame中new的,但在子frame中我有个exit按钮,点该按钮只关闭子frame,此时我在子frame中该如何coding? (子frame没有new自己的对象,又该如何自己dispose())
      

  7.   

    public void setDefaultCloseOperation(int operation) 
    operation的值有operation ==DO_NOTHING_ON_CLOSE 
          operation ==HIDE_ON_CLOSE 
          operation ==DISPOSE_ON_CLOSE 
          operation ==EXIT_ON_CLOSE
      

  8.   

    我那个按钮的action代码如下
    void jButton1_actionPerformed(ActionEvent e) {
            setDefaultCloseOperation(EXIT_ON_CLOSE) ;
    }是这样的吗? (还是关不了)
      

  9.   

    this.dispose()解决了,谢啦,给分.  :-)
      

  10.   

    setDefaultCloseOperation(int operation)是用在什么时候的?
      

  11.   

    setDefaultCloseOperation(EXIT_ON_CLOSE) ;放在构造方法里呀,以便new yourframe()时调用啊