Java Reference
In-Depth Information
import java.io.*;
We can arrange for the frameTitle to be initialized and the default file name to be appended to the
basic window title in the SketchFrame constructor. We can also make sure that
DEFAULT _ DIRECTORY exists and is valid. The following code will do this:
public SketchFrame(String title, Sketcher theApp) {
//setTitle(title); // comment out this line
// Code as before...
frameTitle = title + ": ";
setTitle(frameTitle + filename);
if(!DEFAULT _ DIRECTORY.exists())
if(!DEFAULT _ DIRECTORY.mkdirs())
JOptionPane.showMessageDialog(this,
"Error creating default directory",
"Directory Creation Error",
JOptionPane.ERROR _ MESSAGE);
}
Since we will be implementing the event handling for the Fi le menu, you can remove or comment out
the statements from the constructor that disable the actions for this:
// Disable actions
//saveAction.setEnabled(false);
//closeAction.setEnabled(false);
//printAction.setEnabled(false);
If you recompile Sketcher and run it, you should now see the default file name for a sketch displayed in
the title bar.
Search WWH ::




Custom Search