Java Reference
In-Depth Information
view = new SketchView(this); // Create the view
sketch.addObserver((Observer)view); // Register the view with the model
window.getContentPane().add(view, BorderLayout.CENTER);
window.setVisible(true);
}
// Return a reference to the application window
public SketchFrame getWindow() {
return window;
}
// Return a reference to the model
public SketchModel getModel() {
return sketch;
}
// Return a reference to the view
public SketchView getView() {
return view;
}
// Handler class for window events
class WindowHandler extends WindowAdapter {
// Handler for window closing event
public void windowClosing(WindowEvent e) {
// Code to be added here later...
}
}
private SketchModel sketch; // The data model for the sketch
private SketchView view; // The view of the sketch
private static SketchFrame window; // The application window
private static Sketcher theApp; // The application object
}
There is no code in the windowClosing() method at present, so this assumes we have restored
EXIT _ ON _ CLOSE as the default closing action in the SketchFrame class. We will be adding code to
the windowClosing() method when we get to save sketches on disk. The SketchFrame constructor
needs to be modified as follows:
public SketchFrame(String title, Sketcher theApp) {
setTitle(title); // Set the window title
this.theApp = theApp;
setJMenuBar(menuBar); // Add the menu bar to the window
setDefaultCloseOperation(EXIT _ ON _ CLOSE); // Default is exit the application
// Rest of the constructor as before...
}
You need to add the theApp variable to the SketchFrame class:
Search WWH ::




Custom Search