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:
- A MOMENTARY button will stay PRESSED only as long as the mouse is down over it.
- A TOGGLE button will become PRESSED if NOT_PRESSED, and NOT_PRESSED if PRESSED when the mouse
button is pressed over the MightyButton.
- A PERMANENT button will stay PRESSED forever, once PRESSED.
- A RADIO button is used with the MightyRadioButtonGroup for radio button functionality.
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
-
DISABLED
-
-
MOMENTARY
-
-
NOT_PRESSED
-
-
PERMANENT
-
-
PRESSED
-
-
RADIO
-
-
TOGGLE
-
-
MightyButton(Applet, String)
- Constructor for a MOMENTARY MightyButton with no text put onto the button.
-
MightyButton(Applet, String, String, int)
- Construct an image button.
-
MightyButton(String, String, int)
- Construct an image button.
-
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.
-
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.
-
buttonReact()
- INTERNAL USE ONLY.
This method implements the button's type.
-
calculateTextOffsets()
- INTERNAL USE ONLY.
This method calculates the offset for placing text centered within the button,
given the current font and button size.
-
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.
-
GetButtonType()
- Returns the type of this button, as MOMENTARY, PERMANENT, TOGGLE, or RADIO
-
getMinimumSize()
- The minimum size is the size necessary to display the entire image that makes
up the button.
-
getPreferredSize()
- The preferred dimension is in fact the same as the minimum size.
-
GetState()
- This method returns the current state of the button using the enumerated button
states: PRESSED, NOT_PRESSED, and DISABLED.
-
imageUpdate(Image, int, int, int, int, int)
- This method is of no great importance.
-
mouseClicked(MouseEvent)
-
-
mouseEntered(MouseEvent)
-
-
mouseExited(MouseEvent)
-
-
mousePressed(MouseEvent)
- INTERNAL USE ONLY.
Mouse down causes the button to be pressed if the button is enabled.
-
mouseReleased(MouseEvent)
- INTERNAL USE ONLY.
When the mouse button goes up, the button reacts.
-
paint(Graphics)
- INTERNAL USE ONLY.
This method paints the whole kit-and-caboodle.
-
SetButtonText(String)
- This method sets the text that is placed on top of the button's image.
-
SetButtonType(int)
- Sets the type of this button, to MOMENTARY, PERMANENT, TOGGLE, or RADIO
-
SetFont(Font)
- This method sets font that the aforementioned button text is drawn in.
-
SetImages(Image, Image, Image)
- This method sets the images that will be used for the button's states.
-
SetState(int)
- This method sets the state of the button using the enumerated button states:
PRESSED, NOT_PRESSED, and DISABLED.
-
SetTextColor(Color)
- This method sets the color of the text that the very much aforementioned button
text is drawn in.
MOMENTARY
public static final int MOMENTARY
RADIO
public static final int RADIO
PERMANENT
public static final int PERMANENT
TOGGLE
public static final int TOGGLE
PRESSED
public static final int PRESSED
NOT_PRESSED
public static final int NOT_PRESSED
DISABLED
public static final int DISABLED
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.
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)?
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.
GetButtonType
public int GetButtonType()
- Returns the type of this button, as MOMENTARY, PERMANENT, TOGGLE, or RADIO
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
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).
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.
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.
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.
getPreferredSize
public Dimension getPreferredSize()
- The preferred dimension is in fact the same as the minimum size.
- Overrides:
- getPreferredSize in class Component
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
GetState
public int GetState()
- This method returns the current state of the button using the enumerated button
states: PRESSED, NOT_PRESSED, and DISABLED.
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.
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.
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.
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.
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
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.
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.
mouseClicked
public void mouseClicked(MouseEvent evt)
mouseEntered
public void mouseEntered(MouseEvent evt)
mouseExited
public void mouseExited(MouseEvent evt)
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.
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
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