本文介绍了如何使用FileDialog的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我创建了一个接口,我想增加一个功能,允许用户打开一个文件。我使用AWT。我不知道如何使用FileDialog的。能否请您给我解释一个这样的例子还是不错的链接?
I created an interface and I'd like to add a function that allows user to open a file. I'm using AWT. I don't understand how to use FileDialog. Can you please give me an example or a good link that explain this?
推荐答案
一个完整的code例如,文件过滤:
A complete code example, with file filtering:
FileDialog fd = new FileDialog(yourJFrame, "Choose a file", FileDialog.LOAD);
fd.setDirectory("C:\\");
fd.setFile("*.xml");
fd.setVisible(true);
String filename = fd.getFile();
if (filename == null)
System.out.println("You cancelled the choice");
else
System.out.println("You chose " + filename);
这篇关于如何使用FileDialog的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!