Java Reference
In-Depth Information
} catch(Exception e) {
System.out.println(e);
JOptionPane.showMessageDialog(SketchFrame.this,
"Error reading a sketch file.",
"File Input Error",
JOptionPane.ERROR _ MESSAGE);
}
}
The SketchModel object that is read from the file is passed to a new method in the Sketcher class
insertModel() . This method has to replace the current sketch with the new one that is passed as the
argument. We can implement the method like this:
public void insertModel(SketchModel newSketch) {
sketch = newSketch; // Store the new sketch
sketch.addObserver((Observer)view); // Add the view as observer
sketch.addObserver((Observer)window); // Add the app window as
// observer
view.repaint(); // Repaint the view
}
After we have loaded the new model, we update the window title bar and record the status as
unchanged in the SketchFrame object. If you compile Sketcher once more, you can give the file open
operation a workout.
Don't forget to try out the tooltip for the O pen button. You should see the shortcut key combination
Alt+O appended to the tooltip text.
Search WWH ::




Custom Search