Java Reference
In-Depth Information
import javax.swing.*;
import static java.awt.event.InputEvent.*; // For modifier constants
import java.awt.Color;
import static java.awt.Color.*;
import static Constants.SketcherConstants.*;
public class SketcherFrame extends JFrame {
// Constructor
public SketcherFrame(String title) {
setTitle(title); // Set the window title
setJMenuBar(menuBar); // Add the menu bar to the window
setDefaultCloseOperation(EXIT_ON_CLOSE);
// Code to create the File menu...
// Construct the Elements drop-down menu
elementMenu.add(lineItem = new JRadioButtonMenuItem(
"Line", elementType==LINE));
elementMenu.add(rectangleItem = new JRadioButtonMenuItem(
"Rectangle", elementType==RECTANGLE));
elementMenu.add(circleItem = new JRadioButtonMenuItem(
"Circle", elementType==CIRCLE));
elementMenu.add(curveItem = new JRadioButtonMenuItem(
"Curve", elementType==CURVE));
ButtonGroup types = new ButtonGroup();
// ...plus the rest of the code for grouping the element types as before...
// ...and the code for accelerators for the element types as before...
elementMenu.addSeparator();
elementMenu.add(colorMenu); // Add the sub-menu
colorMenu.add(redItem = new JCheckBoxMenuItem(
"Red", elementColor.equals(RED)));
colorMenu.add(yellowItem = new JCheckBoxMenuItem(
"Yellow", elementColor.equals(YELLOW)));
colorMenu.add(greenItem = new JCheckBoxMenuItem(
"Green", elementColor.equals(GREEN)));
colorMenu.add(blueItem = new JCheckBoxMenuItem(
"Blue", elementColor.equals(BLUE)));
// Add element color accelerators...
// ... plus the rest of the constructor as before...
}
// ...plus the rest of the class as before...
private Color elementColor = DEFAULT_ELEMENT_COLOR; // Current element color
private int elementType = DEFAULT_ELEMENT_TYPE;
// Current element type
}
Search WWH ::




Custom Search