点完JButton立即自动关闭窗口用什么方法!
谢谢各位了!

解决方案 »

  1.   

    一般想关得快...都是模拟的,你可以先Hide这个窗口.
      

  2.   

    可以有System.exit(0);  这是系统退出,呵呵,不过说起来也是关闭窗口了
    也可以是dispose();
    可以是setVisible(false);
    但好象也可是 hide(); 没试过
    import java.awt.*; 
    import java.awt.event.*; 
    import javax.swing.*; 
    import javax.swing.event.*; 
    public class example extends JFrame{ 
        public static void main(String args[]){ 
            JFrame a=new JFrame(); 
             a.setSize(100,80); 
              a.setLayout(new FlowLayout(1)); 
               JButton bta=new JButton("B"); 
               bta.addActionListener(new ActionListener(){ 
        public void actionPerformed(ActionEvent e){ 
         new b(); 
              } 
          }); 
        a.add(bta); 
       a.setVisible(true); 


    class b extends JFrame 

          public b(){         setBounds(110,0,100,80); 
            setLayout(new FlowLayout(1)); 
            JButton btb=new JButton("关闭"); 
            btb.addActionListener(new ActionListener(){ 
            public void actionPerformed(ActionEvent e){ 
             b.this.dispose(); 
            } 
          }); 
            add(btb); 
           setVisible(true); 
         } 
    }
      

  3.   

    通常的关闭都是dispose();
    当然也可以如楼上几位说的先hide();