import javax.swing.*;public class Text2 
{ public static void main(String[] args) 
{
          JFrame f=new JFrame();
          f.setSize(333, 333);
          f.setVisible(true);
          System.out.print(11111);
}

}这个程序怎么让f关闭?????谁帮我添下代码

解决方案 »

  1.   

    f.addWindowListener(new WindowAdapter(){ public void windowClosed(WindowEvent e) {
    System.exit(0);
    }

    });
      

  2.   

    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      

  3.   

    嗯,,,就是像三楼四楼这样的吧
    f.dispose();会释放资源,好像问了四五个人,只有一个人经常这样做,
      

  4.   

    import java.awt.event.*;
    import javax.swing.*;
    public class Text2 {
    public static void main(String[] args) {
    final JFrame f = new JFrame();
    f.setSize(333, 333);
    f.setVisible(true);
    f.addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent e) {
    f.setVisible(false);
    f.dispose();
    System.exit(0);
    }
    });
    }
    }
      

  5.   

    2楼的用windowClosed可不好啊!
    应该用windowClosing().
    并且f.setVisible(false); 
    f.dispose(); 
    System.exit(0); 
    这样写感觉好一点!