package extensions.awt; import java.awt.*; /** * Delegate Button action event. * * @see java.awt.Button * @see extensions.awt.ActionProtocol * @version 1.0.2 * @author John Webster Small */ public class ButtonAction extends Button implements ActionProtocol { private ActionProtocol ap; /** User defined button id. */ public int id = 0; /** Construct a ButtonAction (i.e. a Button) with * the action to be performed when this button is * clicked. The action is performed automatically * only if this ButtonAction appears within an * FrameExtended or DialogExtended window. * For example: *
*
* import java.awt.*;
* import extensions.awt.*;
*
* public class Main extends FrameExtended
* {
* Main()
* {
* super("ButtonAction Demo",FrameExtended.EXIT_ON_DESTROY);
* add("Center",new ButtonAction("Quit",destroyAdapter()));
* resize(200,50);
* show();
* }
* public static void main(String args[]) { new Main(); }
* }
*
*
* Notice that in the above example that neither the frame's
* handleEvent() or action() methods had to be overrided
* to process the button clicked event!
*
* @param ap action to be performed, i.e. run()
* @see extensions.awt.FrameExtended
* @see extensions.awt.DialogExtended
* @see extensions.awt.ActionProtocol
* @see extensions.awt.MenuItemAction
*/
public ButtonAction(ActionProtocol ap)
{
super();
this.ap = ap;
}
/** Label the button. See constructor above.
* @param label Label displayed on button
* @param ap action to be performed, i.e. run()
*/
public ButtonAction(String label, ActionProtocol ap)
{
super(label);
this.ap = ap;
}
/** Label and id the button. See constructors above.
* @param label Label displayed on button
* @param id user defined button id
* @param ap action to be performed, i.e. run()
*/
public ButtonAction(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 and DialogExtended.
* @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
* @see extensions.awt.DialogExtended#handleEvent
*/
public final void action(Component forward, Event evt, Object what)
{ ap.action(forward,evt,what); }
}