用一个按扭来关闭JFrame,用this.dispose();不会引发closing事件。
有什么办法吗?

解决方案 »

  1.   

    LZ得先确定 this.dispose();中的this是否是指代JFrame
    猜测可能你是这样添加事件的:JButton.addActionListener(new ActionListener(){
        public void actionPerformed(ActionEvent e){
            this.dispose();
        } 
    });在这种情况下,this指代的就是ActionListener而不是JFrame
      

  2.   

    没有用内部类,用的是JBulder自动生成的方式。this是写在JFrame中的方法里的。如果是写在内部类中JFrame也不会关闭。现在是JFrame关闭了,可是写在Closing中的代码没有执行。
      

  3.   

    直接用System.exit(0)关闭就行了JButton.addActionListener(new ActionListener(){
        public void actionPerformed(ActionEvent e){
            System.exit(0);
        } 
    });
      

  4.   

    exit(0);是退出程序,我要的是关闭一个窗口。在关闭时能引发closing事件。
      

  5.   

    Frame添回监听事件
    class ClosedWindow extends WindowAdapter {
        private LoginUI adaptee;
        ClosedWindow(LoginUI adaptee){
            this.adaptee = adaptee;
        }    public void windowClosing(WindowEvent e) {
            adaptee.windowClosed();
        }
    }
      

  6.   


    用this.dispose()并没有将窗体的线程结束,也就是说没有将其关闭,只是将窗体隐藏了.在说不是用在按钮上的,而是作用于窗体右上角的那个叉叉上的,想要用按钮关闭程序最好用System.exit(0);       exit(0)是将进程结束掉,这才是真正意义上的关闭窗体. JButton.addActionListener(new   ActionListener(){ 
            public   void   actionPerformed(ActionEvent   e){ 
                    System.exit(0); 
            }   
    }); 
      

  7.   

             dispose();
             System.exit(0);