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
implements MouseListener
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:
$Revision: 1.1.1.1 $, $Date: 1999/11/15 20:37:48 $.
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 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 buttonReact()
INTERNAL USE ONLY.
This method implements the button's type.
 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 getMinimumSize()
The minimum size is the size necessary to display the entire image that makes up the button.
 o getPreferredSize()
The preferred dimension is in fact the same as the minimum size.
 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 mouseClicked(MouseEvent)
 o mouseEntered(MouseEvent)
 o mouseExited(MouseEvent)
 o mousePressed(MouseEvent)
INTERNAL USE ONLY.
Mouse down causes the button to be pressed if the button is enabled.
 o mouseReleased(MouseEvent)
INTERNAL USE ONLY.
When the mouse button goes up, the button reacts.
 o paint(Graphics)
INTERNAL USE ONLY.
This method paints the whole kit-and-caboodle.
 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 static final int MOMENTARY
 o RADIO
 public static final int RADIO
 o PERMANENT
 public static final int PERMANENT
 o TOGGLE
 public static final int TOGGLE
 o PRESSED
 public static final int PRESSED
 o NOT_PRESSED
 public static final int NOT_PRESSED
 o DISABLED
 public static final 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 buttonReact
 public void buttonReact()
INTERNAL USE ONLY.
This method implements the button's type. When the button is released, this method gets called for changing the button's state (if appropriate to the button's type).

 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 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 getPreferredSize
 public Dimension getPreferredSize()
The preferred dimension is in fact the same as the minimum size.

Overrides:
getPreferredSize in class Component
 o getMinimumSize
 public Dimension getMinimumSize()
The minimum size is the size necessary to display the entire image that makes up the button.

Overrides:
getMinimumSize 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 mousePressed
 public void mousePressed(MouseEvent evt)
INTERNAL USE ONLY.
Mouse down causes the button to be pressed if the button is enabled.

Parameters:
event - The MouseEvent that has occured.

 o mouseReleased
 public void mouseReleased(MouseEvent evt)
INTERNAL USE ONLY.
When the mouse button goes up, the button reacts. Consistent with the Java 1.1 event model, the "action" call has been moved to the parent container.

Parameters:
event - The MouseEvent that has occured.

 o mouseClicked
 public void mouseClicked(MouseEvent evt)
 o mouseEntered
 public void mouseEntered(MouseEvent evt)
 o mouseExited
 public void mouseExited(MouseEvent evt)
 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