Java Reference
In-Depth Information
Directory "Sketcher 1 with a status bar"
The method selects the text to be displayed in the pane based on the argument. If something goes wrong
somewhere that results in an invalid element type, the program asserts through the default case.
You can implement the status bar in the SketcherFrame class now. For this you must add a field to the
SketcherFrame class that stores a reference to the status bar, modify the SketcherFrame class constructor
to add the status bar to the content pane of the window, and extend the actionPerformed() methods in the
TypeAction and ColorAction classes to update the status bar when the element type or color is altered.
TRY IT OUT: The Status Bar in Action
You can add the following statement to the SketcherFrame class to define the status bar as a data mem-
ber, following the members that define the menu bar and toolbar:
private StatusBar statusBar = new StatusBar();
// Window
status bar
You create statusBar as a data member so that it can be accessed throughout the class definition, in-
cluding from within the Action classes. You need to add one statement to the end of the SketcherFrame
class constructor:
public SketcherFrame(String title, Sketcher theApp) {
// Constructor code as before...
getContentPane().add(statusBar, BorderLayout.SOUTH);
// Add the
statusbar
}
Directory "Sketcher 1 with a status bar"
This adds the status bar to the bottom of the application window. To update the status bar when the ele-
ment type changes, you can add one statement to the actionPerformed() method in the inner class
TypeAction :
public void actionPerformed(ActionEvent e) {
elementType = typeID;
setChecks(elementMenu, e.getSource());
statusBar.setTypePane(typeID);
}
Directory "Sketcher 1 with a status bar"
Search WWH ::




Custom Search