Java Reference
In-Depth Information
occurred. You assume that the user might want to retry the operation, so you just return
false
from the
method rather than terminating the application.
You can now put together the code that handles the Save menu item event.
TRY IT OUT: Saving a Sketch
The code to initiate handling the Save menu item event goes in the
actionPerformed()
method of the
FileAction
inner class. You have done all the real work by implementing the
saveOperation()
and
saveSketch()
methods, so it amounts to just one statement:
public void actionPerformed(ActionEvent e) {
if(this == saveAction) {
saveOperation();
return;
// else if blocks as before...
}
Directory "Sketcher 1 saving a sketch to a file"
You can recompile Sketcher and run it again. The Save menu item and toolbar button should now be
working. When you select either of them, you should get the dialog displayed in
Figure 21-1
, as long as
you have created a sketch to save. Note that you cannot save a new empty sketch because it is unchanged.