解决方案 »

  1.   

    package test;import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;import javax.swing.JFrame;public class TestFrame extends JFrame {    public TestFrame() {
            this.setSize(400,300);
            //this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//第一个方法
            this.addWindowListener(new WindowAdapter()
            {
                @Override
                public void windowClosing(WindowEvent e) {
                    // TODO Auto-generated method stub
                    super.windowClosing(e);
                    System.exit(0);
                }
            });
        }
        public static void main(String[] args) {
            TestFrame frame = new TestFrame();
            frame.setVisible(true);
        }
    }两个方法都可以啊