Copyright (c) SEMM NL All rights reserved.
Author : Paul Hamaker. Part of JavaLessons.com
The JFrame contains the menubar,...
filled with menus,...
When this menuitem is chosen, ...
this actionPerformed will be called.
If, however, one of these is chosen,...
this other actionPerformed in MenuSw is called.
This is possible, because in the init of MenuSw we pass a reference to the applet instance to the JFrame instance, ...
that is saved.
The on-off menuitem...
requires a different technique :
When chosen, this method is called.
Enable or disable the toolssmt item,...
based on the item being checked or unchecked.
This is allowed,...
because the class also implements ItemListener.
Ctrl-t for the viewsize item.
The same action command-string for a menuitem and the button on the applet.
Both are handled here.
Changing the menu interface during runtime can be done by using the appropriate methods.
As of 1.3 you can unify the action handling for buttons, toolbar buttons and menuitems.
We use this inner class to handle...
this button and menuitem.
Both get the same text,...
the same picture,...
the same description,...
the same mnemonic, Alt-d, as of 1.4, and...
the same handling.
BOTH are disabled after a few actionPerformed calls.
The class AbstractAction implements the Action interface, that extends ActionListener.
The techniques shown can also be used on a stand-alone JFrame application.
JApplet can have a menu, too.