窗体上的关闭按钮不是调用的你写的这个方法关闭的。它调用的是windowListener里的关闭方法。你应该在构造函数里添加windowListener的监听,即
addWindowListener(new WindowListener()

 public void woidowClosing(WindowEvent e)
  {System.exit(0)}
 });

解决方案 »

  1.   

    可是我按照你说的把这个加上去以后,它就出来这个:
    <anonymous class of TestFrame()> should be declared abstract; it does not define windowOpened(WindowEvent) in at line...
    请问这是怎么回事啊???
    thanksthanks!!!真的很急啊。。
      

  2.   

    这是因为WindowListener中有不只一个的方法声明。WindowAdapter包装了WindowListener,应改为:
    addWindowListener(new WindowAdapter()

     public void woidowClosing(WindowEvent e)
      {System.exit(0)}
     });注:
       WindowAdapter在java.awt.event包中。