为什么有java界面程序关闭不了呢?

有时我感觉真的好迷茫 2008-10-02 09:31:24
代码如下:
import java.io.*;
import java.awt.*;
public class FileDisplay
{
public static void main(String[] args)
{
Frame f = new Frame(" Test For FileDialog");
TextArea text = new TextArea(40,400);
f.add(text);
f.setSize(600,500);
f.setVisible(true);

FileDialog fd = new FileDialog(f,"文件对话框",FileDialog.LOAD);
fd.setVisible(true);
String path = fd.getDirectory();
String name = fd.getFile();
String si = path + name;

File file = new File(si);
try{
BufferedReader input = new BufferedReader(new FileReader(file));
String s;
s = input.readLine();
while(s!=null)
{
text.append(s + "\n");
s = input.readLine();
}
input.close();
}catch(IOException e){e.printStackTrace();}
}
}

当创建出界面时,不管点击X号,还是选接系统菜单,就是关闭不了程序,只有借助任务管理器才能关闭,不知这是为什么,我遇到好几次这样的情况了。
...全文
272 9 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
software51 2008-10-03
  • 打赏
  • 举报
回复
要关闭Java视窗,需要单独为视窗注册一个关闭监听器才可以!内容写
System.exit(0);
爱摸鱼de老邪 2008-10-03
  • 打赏
  • 举报
回复
或者在前面设置JFrame属性的时候,增加1个f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
ZangXT 2008-10-02
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 java__king 的回复:]
System.out.exit(0)
[/Quote]
晕,连别人的笔误都抄
java__king 2008-10-02
  • 打赏
  • 举报
回复
System.out.exit(0)
悠云guo 2008-10-02
  • 打赏
  • 举报
回复
默认不处理任何事件的
ZHANGBINFLY 2008-10-02
  • 打赏
  • 举报
回复
添加窗口处理事件
sunyujia 2008-10-02
  • 打赏
  • 举报
回复
awt和swing有点不同利用事件监听
然后System.out.exit(0);
http://topic.csdn.net/u/20081001/22/a805c17b-fe62-47e7-903c-4c846fbf341c.html
http://topic.csdn.net/u/20081001/22/ba4cb409-8bbf-4665-b2b6-0517f9c0d1db.html
ZangXT 2008-10-02
  • 打赏
  • 举报
回复

Frame f = new Frame(" Test For FileDialog");
TextArea text = new TextArea(40, 400);
f.add(text);
//增加如下代码
f.addWindowListener(new WindowAdapter() {

@Override
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
f.setSize(600, 500);
f.setVisible(true);
ZangXT 2008-10-02
  • 打赏
  • 举报
回复
增加窗口事件处理关闭.

62,634

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧