package extensions.awt; import java.awt.*; /** * Delegate MenuItem action event. * * @see java.awt.MenuItem * @see extensions.awt.ActionProtocol * @version 1.0.2 * @author John Webster Small */ public class MenuItemAction extends MenuItem implements ActionProtocol { private ActionProtocol ap; /** User defined id. */ public int id = 0; /** Construct a MenuItemAction (i.e. a MenuItem) with * protocol adapter to handle event generated when * menu item is clicked. Must be added to a FrameExtended * to automate callback of action event to the MenuItemAction. * For example: *
*
* import java.awt.*;
* import extensions.awt.*;
*
* class MyModel extends DialogExtended
* {
* MyModel(Frame parent)
* {
* super(parent,"Done",true);
* add("Center",new ButtonAction("Done",destroyAdapter()));
* resize(100,50);
* }
* }
*
* public class Main
* {
* public static void main(String args[])
* {
* Frame f = new FrameExtended("MenuItemAction Demo",FrameExtended.EXIT_ON_DESTROY);
* MyModel mm = new MyModel(f);
* MenuBar mb = new MenuBar();
* Menu actions = new Menu("Actions");
* actions.add(new MenuItemAction("Do It!",mm.showAdapter()));
* mb.add(actions);
* f.setMenuBar(mb);
* f.resize(250,200);
* f.show();
* }
* }
*
*
*
* Notice that in the above example that neither the frame's
* handleEvent() or action() methods had to be overrided
* to process the menu item clicked event!
*
* @param label label displayed as menu item
* @param ap action to be performed, i.e. run()
* @see extensions.awt.FrameExtended
* @see extensions.awt.DialogExtended
* @see extensions.awt.ActionEventProtocol
* @see extensions.awt.ButtonAction
*/
public MenuItemAction(String label, ActionProtocol ap)
{
super(label);
this.ap = ap;
}
/** Label and id the menu item, see constructor above.
* @param label label displayed as menu item
* @param id user defined menu item id
* @param ap action to be performed, i.e. run()
*/
public MenuItemAction(String label, int id, ActionProtocol ap)
{
this(label,ap);
this.id = id;
}
/** Forward the button clicked action event on to
* the action for further processing by the application
* model rather than the GUI. This method is called
* automatically by FrameExtended.
* @param forward the component forwarding action event
* @param evt the event that caused the action
* @param what the action
* @see extensions.awt.ActionProtocol
* @see extensions.awt.FrameExtended#handleEvent
*/
public final void action(Component forward, Event evt, Object what)
{ ap.action(forward,evt,what); }
}