System.exit(1);
或者使用事件
按收事件来关闭窗体

解决方案 »

  1.   

    import javax.swing.*;public class SimpleFrameTest
    {  
       public static void main(String[] args)
       {  
          SimpleFrame frame = new SimpleFrame();
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.show();  
       }
    }class SimpleFrame extends JFrame
    {
       public SimpleFrame()
       {
          setSize(WIDTH, HEIGHT);
       }   public static final int WIDTH = 300;
       public static final int HEIGHT = 200;
    }
      

  2.   

    我想要的就是加少量的代码,只要点击右上角的叉就能关闪,就和windows窗体一样的效果,上面老兄的代码是不是多了点?
      

  3.   


    楼主要求也太高了吧,上面那位的代码已经很精练了啊.我在jb里只拖拉了一点swing控件,设置了一些属性,JBuilder自动生成的代码居然接近了1000行.
      

  4.   

    你用适配器
    frame.addWindowListener(new WindowAdapter()
    {
      {public void widowClosing(WindowEvent e)
      {System.exit(0);}
    });
    }
    或者继承Adapter
    class Frame extends WindowAdapter
    {
       Frame f = new Frame();
       f.addwindowListener(this);
       public void WindowClosing(WindowEvent e)
       {
          System.exit(0);
       }
    }