java生成的awt窗口怎么不能关闭???
答案:2 悬赏:80 手机版
解决时间 2021-03-29 13:44
- 提问者网友:欲望失宠
- 2021-03-29 02:16
java生成的awt窗口怎么不能关闭???
最佳答案
- 五星知识达人网友:怙棘
- 2021-03-29 02:36
import java.awt.*;
import java.awt.event.*;//增加的引入public class frametest {
public static void main(String args[]){
Frame frame1=new Frame();
//增加的代码
frame1.addWindowListener(new WindowAdapter(){
@Override
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
frame1.setSize(300,300);
frame1.setVisible(true);
frame1.setBackground(Color.blue);
}
}
import java.awt.event.*;//增加的引入public class frametest {
public static void main(String args[]){
Frame frame1=new Frame();
//增加的代码
frame1.addWindowListener(new WindowAdapter(){
@Override
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
frame1.setSize(300,300);
frame1.setVisible(true);
frame1.setBackground(Color.blue);
}
}
全部回答
- 1楼网友:低血压的长颈鹿
- 2021-03-29 03:19
添加windows事件(此事件方法有六个或者更多),在closing或者close中写System.exit(0);关闭窗口。可以直接继承windowsAdapter只要写其中的几个方法就行(比如你只要关闭方法就不用其他方法了)。
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯