代码如下:
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号,还是选接系统菜单,就是关闭不了程序,只有借助任务管理器才能关闭,不知这是为什么,我遇到好几次这样的情况了。
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号,还是选接系统菜单,就是关闭不了程序,只有借助任务管理器才能关闭,不知这是为什么,我遇到好几次这样的情况了。
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);
然后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
System.exit(0);