setDefaultCloseOperation(3);
加上这句试试!

解决方案 »

  1.   

    可以代码贴出来吗?这样很难找到问题所在的,如果不方便的话,可以发email, [email protected]
      

  2.   

    to shihb():我用的是awt,好象你说的那个东东不能通过编译.
      

  3.   

    下面是代码:
    import java.awt.*;
    public class my3 extends Frame
    {
    public static void main(String args[])
    {
    my3 frame1=new my3();
    frame1.setSize(200,200);
    frame1.setTitle("stand a label object");
    Label label1=new Label("this is a label object");
    Font font=new Font("Serif",Font.ITALIC|Font.BOLD,20);
    label1.setFont(font);
    frame1.add(label1);
    frame1.setVisible(true);
    }
    }
      

  4.   

    import java.awt.*;
    import java.awt.event.*;
    public class Frametest extends Frame
    {
         public Frametest(String title)
         {
            super(title);  
    addWindowListener(new WindowAdapter()
    {
    public void windowClosing(WindowEvent e)
    {
    System.exit(0);
    }
    });
         }
         public static void main (String args[])
         {
            Frametest test=new Frametest("This is title");
            test.setLocation(100,100);
            test.setSize(300,300);
            test.setVisible(true);
          }
    }
      

  5.   

    在 myframe中添加下面的方法
    protected void processWindowEvent(WindowEvent e) {
        super.processWindowEvent(e);
    }
    你必须对你的窗体的关闭事件进行处理,这样才能关闭
    上面的这个方法就是说让系统自己去处理,就自动关闭了
    如果你要想在关闭前做一些事情就可以这样
    protected void processWindowEvent(WindowEvent e) {
        super.processWindowEvent(e);
        if(e.getID() == WindowEvent.WINDOW_CLOSING) {
            //要处理的代码    
        }
    }
      

  6.   

    哦,原来你继承的是Frame
    那我这个也不一定能行了
    如果你把你的程序该成extends JFrame
    我的就没问题了
      

  7.   

    我觉得有两种办法,一种是在你的frame中加一个“退出”button,其中有System.exit(0);即可!
    另一种办法就是让frame上的关闭button有效。也就是在frame定义的地方加上:
    setDefaultCloseOperation(3);
    其中“3”就是使button有效的参数。你是不是位置放的不对?
      

  8.   

    你的程序中应该是:
    frame1.setDefaultCloseOperation(3);
      

  9.   

    CanFly(我会飞)的方法应该是对的!
    还有其他方法,但是大同小异了!