Class dpscomponents.button.MightyButton
All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class dpscomponents.button.MightyButton

java.lang.Object
   |
   +----java.awt.Component
           |
           +----java.awt.Canvas
                   |
                   +----dpscomponents.button.MightyButton

public class MightyButton
extends Canvas
The MightyButton class is used to create various types of buttons, MOMENTARY, TOGGLE, PERMANENT, or RADIO. The appearance of the MightyButton in its states (PRESSED, NOT_PRESSED, and DISABLED) is determined by the buttonName passed to the constructor (this name is used to load in the 3 GIFs). See constructor for details.

Using the MightyRadioButtonGroup class supplied, any MightyButton can be a radio button.

Button Types:

Behavior is added to MightyButton by subclassing it and overriding the action method.

Version:
1.80, 21 February 1996

Changes from last version

Author:
Benjamin "Quincy" Cabell V, Besiex Software, built from ImageButton by Adam Doppelt

Variable Index

 o DISABLED
 o MOMENTARY
 o NOT_PRESSED
 o PERMANENT
 o PRESSED
 o RADIO
 o TOGGLE

Constructor Index

 o MightyButton(Applet, String)
Constructor for a MOMENTARY MightyButton with no text put onto the button.
 o MightyButton(Applet, String, String, int)
Construct an image button.
 o MightyButton(String, String, int)
Construct an image button.

Method Index

 o action()
INTERNAL USE ONLY.
This method is called when the button is pressed.
 o addButtonForRadioPress(MightyButton)
INTERNAL USE ONLY.
This method gets called by the MightyRadioButtonGroup when a radio button is added to the group this button is in.
 o autoResize()
INTERNAL USE ONLY.
This method is called to recalculate the necessary dimensions of the button, based upon the button image's size, then resize the button to this size.
 o calculateTextOffsets()
INTERNAL USE ONLY.
This method calculates the offset for placing text centered within the button, given the current font and button size.
 o clearAllButtonForRadioPress()
INTERNAL USE ONLY.
This method gets called by the MightyRadioButtonGroup when a radio button is added to the group this button is in, to clear the current list so the new list can be added.
 o GetButtonType()
Returns the type of this button, as MOMENTARY, PERMANENT, TOGGLE, or RADIO
 o GetState()
This method returns the current state of the button using the enumerated button states: PRESSED, NOT_PRESSED, and DISABLED.
 o imageUpdate(Image, int, int, int, int, int)
This method is of no great importance.
 o minimumSize()
The minimum size is the size necessary to display the entire image that makes up the button.
 o mouseDown(Event, int, int)
INTERNAL USE ONLY.
Mouse down causes the button to be pressed if the button is enabled.
 o mouseUp(Event, int, int)
INTERNAL USE ONLY.
When the mouse button goes up, the button reacts, and the action is called.
 o paint(Graphics)
INTERNAL USE ONLY.
This method paints the whole kit-and-caboodle.
 o preferredSize()
The preferred dimension is in fact the same as the minimum size.
 o SetButtonText(String)
This method sets the text that is placed on top of the button's image.
 o SetButtonType(int)
Sets the type of this button, to MOMENTARY, PERMANENT, TOGGLE, or RADIO

 o SetFont(Font)
This method sets font that the aforementioned button text is drawn in.
 o SetImages(Image, Image, Image)
This method sets the images that will be used for the button's states.
 o SetState(int)
This method sets the state of the button using the enumerated button states: PRESSED, NOT_PRESSED, and DISABLED.
 o SetTextColor(Color)
This method sets the color of the text that the very much aforementioned button text is drawn in.

Variables

 o MOMENTARY
  public final static int MOMENTARY
 o RADIO
  public final static int RADIO
 o PERMANENT
  public final static int PERMANENT
 o TOGGLE
  public final static int TOGGLE
 o PRESSED
  public final static int PRESSED
 o NOT_PRESSED
  public final static int NOT_PRESSED
 o DISABLED
  public final static int DISABLED

Constructors

 o MightyButton
  public MightyButton(String theButtonName,
                      String theButtonText,
                      int theButtonType)
Construct an image button. An image button is composed of three images, one for each possible state of the button. If null is passed for pressed and/or disabled, those states will draw using the normal image. Many thanks to Bobby Arnold (rharnold@csupomona.edu) for his recommendation on getting the Applet's handle from within a component.

Parameters:
theButtonName - The file name of the button, without the _p.gif,_n.gif,_d.gif. Here's how it works: I tack on "_p.gif" for the image of a pressed button, "_n.gif" for the image of a not-pressed button, and "_d.gif" for the image of a disabled button. So, if you pass in "iAmAButton" as theButtonName, this code will load in iAmAButton_p.gif, iAmAButton_n.gif, and iAmAButton_d.gif. Get it? It was meant to make things easy. You also have to specify the location of the button image file here. In the case of a stand-alone app this must be the absolute path to the file, in the case of an applet, this is relative to the codebase.

theButtonText - When the button is displayed, you can have it displayed with text on top of it (so people know what the button does). Text color, font, and size can all be set (default color is black, default font is Helvetica Bold 12).

theButtonType - What kind of button is this? MOMENTARY, TOGGLE, PERMANENT, or RADIO.
 o MightyButton
  public MightyButton(Applet theApplet,
                      String theButtonName)
Constructor for a MOMENTARY MightyButton with no text put onto the button.

Parameters:
theApplet - A handle to the Applet; This is required for using getDocumentBase(), getCodeBase(), and getImage(URL, String). There should be, nay, must be a way to get the Applet handle without having to pass it in, but I couldn't figure one out. Anyone know if it can be done (and how)?

 o MightyButton
  public MightyButton(Applet theApplet,
                      String theButtonName,
                      String theButtonText,
                      int theButtonType)
Construct an image button. This constructor is included only for backward compatability. The handle to the Applet need not be passed to the constructor any more.

Methods

 o GetButtonType
  public int GetButtonType()
Returns the type of this button, as MOMENTARY, PERMANENT, TOGGLE, or RADIO
 o SetButtonType
  public void SetButtonType(int theType)
Sets the type of this button, to MOMENTARY, PERMANENT, TOGGLE, or RADIO

Parameters:
theType - The button type to make this button, MOMENTARY, PERMANENT, TOGGLE, or RADIO
 o addButtonForRadioPress
  public void addButtonForRadioPress(MightyButton theButton)
INTERNAL USE ONLY.
This method gets called by the MightyRadioButtonGroup when a radio button is added to the group this button is in. Each time a new button is added to the group, the old list is cleared, then this method gets called for each button in the group.

Parameters:
theButton - The MightyButton that gets added to this button's list of radio buttons to unpress when this button is pressed.
 o clearAllButtonForRadioPress
  public void clearAllButtonForRadioPress()
INTERNAL USE ONLY.
This method gets called by the MightyRadioButtonGroup when a radio button is added to the group this button is in, to clear the current list so the new list can be added.
 o action
  public boolean action()
INTERNAL USE ONLY.
This method is called when the button is pressed. Override it to add behavior to the button. The value of the returned boolean is true the event was handled and will NOT be processed by the MightyButtonWithCallback handler...
 o autoResize
  public void autoResize()
INTERNAL USE ONLY.
This method is called to recalculate the necessary dimensions of the button, based upon the button image's size, then resize the button to this size. The reason this code is called add behavior to the button.
 o preferredSize
  public Dimension preferredSize()
The preferred dimension is in fact the same as the minimum size.
Overrides:
preferredSize in class Component
 o minimumSize
  public Dimension minimumSize()
The minimum size is the size necessary to display the entire image that makes up the button.
Overrides:
minimumSize in class Component
 o GetState
  public int GetState()
This method returns the current state of the button using the enumerated button states: PRESSED, NOT_PRESSED, and DISABLED.
 o SetState
  public void SetState(int theState)
This method sets the state of the button using the enumerated button states: PRESSED, NOT_PRESSED, and DISABLED.

Parameters:
theState - The state to which to set the button.
 o SetButtonText
  public void SetButtonText(String theButtonText)
This method sets the text that is placed on top of the button's image.

Parameters:
theButtonText - The text to display in the button.
 o SetFont
  public void SetFont(Font theFont)
This method sets font that the aforementioned button text is drawn in.

Parameters:
theFont - The font to use for the button's text.
 o SetTextColor
  public void SetTextColor(Color theColor)
This method sets the color of the text that the very much aforementioned button text is drawn in.

Parameters:
theColor - The color to use for the button's text.
 o SetImages
  public void SetImages(Image theImageOfNotPressed,
                        Image theImageOfPressed,
                        Image theImageOfDisabled)
This method sets the images that will be used for the button's states. This could be used if all of a sudden you wanted to change the appearance of a button, after it had already been instantiated.

Parameters:
theImageOfNotPressed - The image for the button when button's state is NOT_PRESSED

theImageOfPressed - The image for the button when button's state is PRESSED

theImageOfDisabled - The imaged for the button when button's state is DISABLED
 o mouseDown
  public boolean mouseDown(Event event,
                           int x,
                           int y)
INTERNAL USE ONLY.
Mouse down causes the button to be pressed if the button is enabled.

Parameters:
event - The Event that has occured.

x - The x coordinate of the event.

y - The y coordinate of the event.
Overrides:
mouseDown in class Component
 o mouseUp
  public boolean mouseUp(Event event,
                         int x,
                         int y)
INTERNAL USE ONLY.
When the mouse button goes up, the button reacts, and the action is called.

Parameters:
event - The Event that has occured.

x - The x coordinate of the event.

y - The y coordinate of the event.
Overrides:
mouseUp in class Component
 o calculateTextOffsets
  public void calculateTextOffsets()
INTERNAL USE ONLY.
This method calculates the offset for placing text centered within the button, given the current font and button size.

 o paint
  public void paint(Graphics graphics)
INTERNAL USE ONLY.
This method paints the whole kit-and-caboodle.

Parameters:
graphics - The graphics context of this button.
Overrides:
paint in class Canvas
 o imageUpdate
  public boolean imageUpdate(Image image,
                             int infoflags,
                             int x,
                             int y,
                             int width,
                             int height)
This method is of no great importance. So little in importance, I won't even bother telling you what it doesn't do; Because I live in America, a land of passion, liberty, crime, degredation, aluminum, and the finest politicians money can buy. I love the idea of this country. It is the implementation that is beginning to worry me.

Overrides:
imageUpdate in class Component

All Packages  Class Hierarchy  This Package  Previous  Next  Index