Opening an Image File
All the user needs to do to open an image file is to use the File menu's Open… item. When the user selects that item, the actionPerformed method is called. Then, after making sure the Open… item was selected, the code sets the dialog object's mode to FileDialog.LOAD and makes the dialog box visible with the dialog.setVisible(true) call:
public void actionPerformed(ActionEvent event) { if(event.getSource() == menuitem1){ dialog.setMode(FileDialog.LOAD); dialog.setVisible(true); . . .
Setting the File dialog box's mode to FileDialog.LOAD (the only other option is FileDialog.SAVE) makes the dialog box display the File Open dialog box you see in Figure 3.2.
Figure 3.2. Opening a file.
You can see the ...
Get Java™ After Hours: 10 Projects You'll Never Do at Work now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.