请问有谁帮我把窗体关闭的带码告诉我!谢谢了,我急用。

解决方案 »

  1.   

    this.dispose();//先销毁窗口 
    System.exit(0);//退出整个系统
      

  2.   

    import java.awt.*;
    import java.awt.event.*;public class Frame1 extends  WindowAdapter {
      public Frame1() {
        Frame f=new Frame();
        f.setSize(new Dimension(400, 300));
        f.setTitle("Frame1");
        f.addWindowListener(this);
        f.setVisible(true);
      }
      public static void main(String[] s){
        new Frame1();
      }
      public void windowClosing(WindowEvent windowEvent) {
        System.exit(0);
      }
    }
      

  3.   

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

  4.   

    Java codeimport java.awt.*;
    import java.awt.event.*;
    public class fram extends Frame implements ActionListener {
        static Button btn;
        fram(){
            super("Frame with Button");
            setVisible(true);
            btn=new Button("退出");
            setBackground(Color.yellow);
            setForeground(Color.blue);         //setResizable(false);//不可更改大小
             //setSize(380,500);//设置大小         add(btn);
            pack();
            btn.addActionListener(this);
        }
        static void addPerformed(ActionEvent e){
            if (e.getSource()==btn) {
                System.exit(0);    
            }
            }
        public static void main(String[] args) {
            fram frm =new fram();// TODO Auto-generated method stub    }}
    frame1.java:3:   frame1   不是抽象的,并且未覆盖   java.awt.event.ActionListener   中的抽象方法   actionPerformed(java.awt.event.ActionEvent) Java codeimport java.awt.*;
    import java.awt.event.*;public class pel extends Frame implements ActionListener {
        static Button btn;
        pel() {
            super("Panel with button");
            Panel p1 = new Panel();
            add(p1);
            btn=new Button("exit");
            p1.add(btn);
            pack();
            btn.addActionListener(this);
        }    static void addPerformed(ActionEvent e) {
            if (e.getSource()=btn) {
                System.exit(0);
            }
        }    public static void main(String[] args) {
            pel p = new pel();
        }
    }
    F:\000\work\111> javac   pel.java 
    pel.java:4:   pel   不是抽象的,并且未覆盖   java.awt.event.ActionListener   中的抽象方 
    法   actionPerformed(java.awt.event.ActionEvent) 
    public   class   pel   extends   Frame   implements   ActionListener   { 
                  ^ 
    pel.java:17:   意外的类型 
    需要:   变量 
    找到:   值 
                                    if   (e.getSource()=btn)   { 
                                                                  ^ 
    2   错误 
     
     
     
    问题点数:20 回复次数:0 显示所有回复显示星级回复显示楼主回复     
     将帖子提前   加入我的收藏夹   推荐给好友 回复 我要提问 管理帖子 帖子加分