Java Reference
In-Depth Information
exitAction = new FileAction("Exit", 'X', CTRL_DOWN_MASK);
// Initialize the array
FileAction[] actions = {openAction, closeAction, saveAction,
saveAsAction, printAction, exitAction};
fileActions = actions;
}
Directory "Sketcher 6 using Action objects"
Each FileAction object has a NAME field value. Only the actions for the Close and Save As menu items
do not have accelerator keys. You initialize the fileActions array so it holds all the file action referen-
ces.
The helper method in the SketcherFrame class to create the actions for the type menu items in the Ele-
ments menu looks like this:
private void createElementTypeActions() {
lineAction = new TypeAction("Line", LINE, 'L', CTRL_DOWN_MASK);
rectangleAction = new TypeAction("Rectangle", RECTANGLE, 'R',
CTRL_DOWN_MASK);
circleAction = new TypeAction("Circle", CIRCLE,'C',
CTRL_DOWN_MASK);
curveAction = new TypeAction("Curve", CURVE,'U', CTRL_DOWN_MASK);
// Initialize the array
TypeAction[] actions = {lineAction, rectangleAction,
circleAction, curveAction};
typeActions = actions;
}
Directory "Sketcher 6 using Action objects"
This is very similar to the previous method. Each of the actions has a name value and the accelerator key
combination.
Here the code for the helper method to create actions for the Color menu:
private void createElementColorActions() {
redAction = new ColorAction("Red", RED, 'R',
CTRL_DOWN_MASK|ALT_DOWN_MASK);
yellowAction = new ColorAction(
"Yellow", YELLOW, 'Y',
CTRL_DOWN_MASK|ALT_DOWN_MASK);
Search WWH ::




Custom Search