java怎么关闭AWT窗口
importjava.awt.*;importjava.awt.event.*;publicclassawtttextendsFrameimplementsActionL...
import java.awt.*;
import java.awt.event.*;
public class awttt extends Frame implements ActionListener{
Panel panel;
Button button;
//Button button2;
Button changebutton;
Label label;
Label label2;
//TextField text;
int i=1;
public awttt()
{
this.addWindowListener(new WindowAdapter()
{public void windowClossing(WindowEvent e)
{
System.exit(0);
}
});
this.setLayout(new GridLayout(2,1));
changebutton=new Button("next");
changebutton.addActionListener(this);
this.add(changebutton);
panel=new Panel();
panel.setLayout(new CardLayout());
label=new Label("第一层");
panel.add("first",label);
//text=new TextField("第二层");
//panel.add("second",text);
//button2=new Button("第二层");
//panel.add("second",button2);
label2=new Label("第二层");
panel.add("second",label2);
button=new Button("返回");
button.addActionListener(this);
this.add(button);
panel.add("third",button);
this.add(panel);
this.setSize(300,200);
this.setVisible(true);
}
public static void main(String[]args)
{new awttt();}
public void actionPerformed(ActionEvent e)
{if(e.getActionCommand().equals("next"));
{switch(i)
{case 1:((CardLayout)panel.getLayout()).show(panel,"second");
break;
case 2:((CardLayout)panel.getLayout()).show(panel,"third");
break;
case 3:((CardLayout)panel.getLayout()).show(panel,"first");
break;
}i++; if(i==4){i=1;}
}
if(e.getActionCommand().equals("返回"))
{i=1;
((CardLayout)panel.getLayout()).show(panel,"first");
}
}
} 展开
import java.awt.event.*;
public class awttt extends Frame implements ActionListener{
Panel panel;
Button button;
//Button button2;
Button changebutton;
Label label;
Label label2;
//TextField text;
int i=1;
public awttt()
{
this.addWindowListener(new WindowAdapter()
{public void windowClossing(WindowEvent e)
{
System.exit(0);
}
});
this.setLayout(new GridLayout(2,1));
changebutton=new Button("next");
changebutton.addActionListener(this);
this.add(changebutton);
panel=new Panel();
panel.setLayout(new CardLayout());
label=new Label("第一层");
panel.add("first",label);
//text=new TextField("第二层");
//panel.add("second",text);
//button2=new Button("第二层");
//panel.add("second",button2);
label2=new Label("第二层");
panel.add("second",label2);
button=new Button("返回");
button.addActionListener(this);
this.add(button);
panel.add("third",button);
this.add(panel);
this.setSize(300,200);
this.setVisible(true);
}
public static void main(String[]args)
{new awttt();}
public void actionPerformed(ActionEvent e)
{if(e.getActionCommand().equals("next"));
{switch(i)
{case 1:((CardLayout)panel.getLayout()).show(panel,"second");
break;
case 2:((CardLayout)panel.getLayout()).show(panel,"third");
break;
case 3:((CardLayout)panel.getLayout()).show(panel,"first");
break;
}i++; if(i==4){i=1;}
}
if(e.getActionCommand().equals("返回"))
{i=1;
((CardLayout)panel.getLayout()).show(panel,"first");
}
}
} 展开
展开全部
this.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
此处写错了,本来是要 WindowAdapter 适配器类的 windowClosing(WindowEvent e)方法,但是你把方法名写成了windowClossing,
实际为windowClosing (多了个s)
由于WindowAdapter不是接口,是类,所以 即使写错了,也不报编译错误。
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
此处写错了,本来是要 WindowAdapter 适配器类的 windowClosing(WindowEvent e)方法,但是你把方法名写成了windowClossing,
实际为windowClosing (多了个s)
由于WindowAdapter不是接口,是类,所以 即使写错了,也不报编译错误。
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
this.setDefaultCloseOption(JFrame.EXIT_ON_CLOSE);
或者
System.exit(0);
或者
System.exit(0);
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
只看到一段代码,请恕我没有耐心看。。。我不知道你要问的是什么。。。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询