J2EEOnlineJ2EE 





File Dialogs  «Prev  Next»
Lesson 3Choosing files with file dialog boxes
ObjectiveCreate the FileDialog

Familiarize yourself with the use of the FileDialog constructor.


You create a FileDialog object with this constructor:
public FileDialog(Frame parent, String title, int mode)
The Frame is the parent of this file dialog box. This will normally be the main window of the application, the applet's frame, or the frontmost window of the application. Or you can just create a new Frame.
The title argument is simply the title for the file dialog box, normally something like "Please choose the file to open: "
The mode argument is one of the two mnemonic constants FileDialog.LOAD or FileDialog.SAVE. Use FileDialog.LOAD if you want the user to choose a file to open. Use FileDialog.SAVE if you want the user to choose a file to save the data into.
A typical use of this constructor might look like this:


FileDialog fd = new FileDialog(new Frame(),
 "Please choose the file to open:", FileDialog.LOAD);