// dummy Frame, never shown
Frame parent = new Frame();
FileDialog fd = new FileDialog(parent, "Please choose a file:", FileDialog.LOAD);
fd.show();
// program stops here until user selects a file or cancels
String dir = fd.getDirectory();
String file = fd.getFile();
// clean up our windows, they won't be needed again
parent.dispose();
fd.dispose();
if (dir == null || file == null) { // user cancelled the dialog
return null;
}
return new File(dir, file);