setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE )

解决方案 »

  1.   

    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE )
    setDefualtCloseOperation(JFrame.DO_NOTHING_ON_CLOSE)
    setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE)
    setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE)
      

  2.   

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

  3.   

    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE )和下面的意思差不多,上面的是这个窗口关闭,而下面这个会整个程序退出。Frame f = new Frame();
    f.addWindowListener(new WindowAdapter() {
      public void windowClosing(WindowEvent e) {
        System.exit(0);
      }
    });哪个方便用哪个吧!
      

  4.   

    JFrame中有个方法,重载它
      protected void processWindowEvent(WindowEvent e) {
        super.processWindowEvent(e);
        if (e.getID() == WindowEvent.WINDOW_CLOSING) {
          System.exit(0);
        }
      }