import javax.swing.*;
public class WorkOprFrame extends JFrame {  //Overridden so we can exit when window is closed
  protected void processWindowEvent(WindowEvent e) {
    super.processWindowEvent(e);
    if (e.getID() == WindowEvent.WINDOW_CLOSING) {
      System.exit(0);
    }
  }
}

解决方案 »

  1.   

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

  2.   

    可以,但是“绝对绝对绝对..................*100”不推荐使用System.exit(0);首先,你要做的仅仅是关闭一个Frame,倘若你有10个,那么关闭任何一个,岂不是都回导致系统崩溃。
    其次,System.exit(0);会导致很多该做的事情没有做,
    比较
    try { 
      return;/throw new Exception();/System.exit(0);
    } finally {
      System.out.prinln(".......");
    }
    就知道了推荐使用frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);具体的方法名和参数名可能会有出入,
    然后将System.exit(0);--〉dispose();
      

  3.   

    不行啊。。我是在applet中打开了一个frame,我想关闭他,可就是这样都关闭不了饿那位帮忙一下,明天交差了
      

  4.   

    关闭窗口不是用dispose()方法吗?怎么用System.exit(0)呢?这样不就退出整个JVM了吗?