Java Reference
In-Depth Information
Let's start with a status bar at the bottom of the Sketcher application that contains two panes for showing the
current element type and color. Then the user will know exactly what they are about to draw. You can start
by defining the StatusBar class that represents the status bar in the application window. The StatusPane
class that defines a region within the status bar can be an inner class to StatusBar .
Here's an initial stab at the definition for the StatusBar class that you can add to the Sketcher applica-
tion:
// Class defining a status bar
import javax.swing.*;
import java.awt.*;
import javax.swing.border.BevelBorder;
import static Constants.SketcherConstants.*;
class StatusBar extends JPanel {
// Constructor
public StatusBar() {
setLayout(new FlowLayout(FlowLayout.LEFT, 10, 3));
setBackground(Color.LIGHT_GRAY);
setBorder(BorderFactory.createLineBorder(Color.DARK_GRAY));
colorPane = new StatusPane("BLUE", BLUE16);
setColorPane(DEFAULT_ELEMENT_COLOR);
setTypePane(DEFAULT_ELEMENT_TYPE);
add(colorPane);
// Add color pane to status bar
add(typePane);
// Add type pane to status bar
}
// Set color pane contents
public void setColorPane(Color color) {
// Code to set the color pane contents...
}
// Set type pane contents
public void setTypePane (int elementType) {
// Code to set the type pane contents...
}
// Panes in the status bar
private StatusPane colorPane;
private StatusPane typePane;
// Class defining a status bar pane
class StatusPane extends JLabel {
// Rest of the class implementation...
}
}
Directory "Sketcher 1 with a status bar"
Because the StatusBar class imports the names of static members of the SketcherConstants class from
the Constants package, all the constants that represent possible element types and colors and the icons used
Search WWH ::




Custom Search