|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectmhframework.gui.MHGUIComponent
mhframework.gui.MHGUIButton
public class MHGUIButton
This class provides graphical image-based buttons within my game framework.
How to add buttons to a game screen:
KNOWN ISSUE: Text buttons (TYPE_TEXT_BUTTON) do not render properly in windowed mode.
Field Summary | |
---|---|
protected java.awt.event.ActionListener |
actionListener
ActionEvent listener |
static int |
BUTTON_DOWN
Indicates button is pressed down |
static int |
BUTTON_NORMAL
Indicates button is in normal state |
static int |
BUTTON_OVER
Indicates that mouse is over the button |
protected MHGUILabel |
caption
The text caption on the button |
static java.awt.Color |
DOWN_COLOR
|
protected java.awt.Color |
downColor
Color of down state |
protected java.awt.Image |
icon
The icon on the button |
static java.lang.String |
IMAGE_TYPE_GIF
Indicates that button image files are in GIF format. |
static java.lang.String |
IMAGE_TYPE_JPG
Indicates that button image files are in JPEG (JPG) format. |
static java.lang.String |
IMAGE_TYPE_PNG
Indicates that button image files are in PNG format. |
protected java.awt.Image[] |
images
Array of button images for BUTTON_NORMAL, BUTTON_DOWN, and BUTTON_OVER states. |
protected java.awt.event.KeyListener |
keyListener
|
protected java.awt.event.MouseListener |
mouseListener
|
protected java.awt.event.MouseMotionListener |
mouseMotionListener
|
static java.awt.Color |
NORMAL_COLOR
|
protected java.awt.Color |
normalColor
Color of normal state |
static java.awt.Color |
OVER_COLOR
|
protected java.awt.Color |
overColor
Color of mouseover state |
protected int |
type
Indicates type of button (See TYPE_ constants) |
static int |
TYPE_ICON_BUTTON
Indicates button with icon and text. |
static int |
TYPE_IMAGE_BUTTON
Indicates that the entire button is a single image. |
static int |
TYPE_TEXT_BUTTON
Indicates button with text only. |
Fields inherited from class mhframework.gui.MHGUIComponent |
---|
focusable, height, state, width |
Constructor Summary | |
---|---|
MHGUIButton()
Default constructor which creates a text-only button. |
|
MHGUIButton(java.awt.Image normal,
java.awt.Image down,
java.awt.Image over)
Default constructor which creates a text-only button. |
|
MHGUIButton(java.lang.String filenamebase)
Overloaded constructor which creates an image button from GIF files. |
|
MHGUIButton(java.lang.String filenamebase,
java.lang.String imagetype)
Overloaded constructor which creates an image button from files of a specified type. |
Method Summary | |
---|---|
void |
actionPerformed(java.awt.event.ActionEvent e)
|
void |
addActionListener(java.awt.event.ActionListener listener)
|
void |
addKeyListener(java.awt.event.KeyListener listener)
|
void |
addMouseListener(java.awt.event.MouseListener listener)
|
void |
addMouseMotionListener(java.awt.event.MouseMotionListener listener)
|
void |
advance()
Tells an object to update its data. |
java.lang.String |
getCaptionText()
|
java.awt.Color |
getDownColor()
Returns the downColor. |
java.awt.Font |
getFont()
|
java.awt.Image |
getIcon()
Returns the icon. |
java.awt.Color |
getNormalColor()
Returns the normalColor. |
java.awt.Color |
getOverColor()
Returns the overColor. |
int |
getType()
Returns the type. |
void |
keyPressed(java.awt.event.KeyEvent e)
|
void |
keyReleased(java.awt.event.KeyEvent e)
|
void |
keyTyped(java.awt.event.KeyEvent e)
|
void |
mouseClicked(java.awt.event.MouseEvent e)
|
void |
mouseMoved(java.awt.event.MouseEvent e)
|
void |
mousePressed(java.awt.event.MouseEvent e)
Sets the button to its "pressed" state if it is enabled and the click event took place over the button. |
void |
mouseReleased(java.awt.event.MouseEvent e)
Simulates the "clicking" of a button by informing the action listener that a click event took place. |
void |
render(java.awt.Graphics2D g)
Tells an object to draw itself onto the sent Graphics object. |
void |
setDownColor(java.awt.Color downColor)
Sets the downColor. |
void |
setFont(java.awt.Font f)
|
void |
setForeColor(java.awt.Color c)
|
void |
setIcon(java.awt.Image icon)
Sets the icon. |
void |
setNormalColor(java.awt.Color normalColor)
Sets the normalColor. |
void |
setOverColor(java.awt.Color overColor)
Sets the overColor. |
void |
setText(java.lang.String text)
|
void |
setType(int type)
Sets the type. |
void |
showBounds(boolean show)
|
protected java.awt.geom.Rectangle2D |
updateBounds()
|
Methods inherited from class mhframework.gui.MHGUIComponent |
---|
getBounds, getHeight, getWidth, getX, getY, hasFocus, isEnabled, isVisible, mouseDragged, mouseEntered, mouseExited, paint, setEnabled, setFocus, setFocusable, setHeight, setPosition, setSize, setVisible, setWidth, setX, setY |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int TYPE_TEXT_BUTTON
public static final int TYPE_ICON_BUTTON
public static final int TYPE_IMAGE_BUTTON
public static final java.lang.String IMAGE_TYPE_GIF
public static final java.lang.String IMAGE_TYPE_PNG
public static final java.lang.String IMAGE_TYPE_JPG
public static final int BUTTON_NORMAL
public static final int BUTTON_DOWN
public static final int BUTTON_OVER
public static final java.awt.Color NORMAL_COLOR
public static final java.awt.Color DOWN_COLOR
public static final java.awt.Color OVER_COLOR
protected MHGUILabel caption
protected java.awt.Color normalColor
protected java.awt.Color downColor
protected java.awt.Color overColor
protected java.awt.Image icon
protected java.awt.Image[] images
protected int type
protected java.awt.event.ActionListener actionListener
protected java.awt.event.KeyListener keyListener
protected java.awt.event.MouseListener mouseListener
protected java.awt.event.MouseMotionListener mouseMotionListener
Constructor Detail |
---|
public MHGUIButton()
public MHGUIButton(java.awt.Image normal, java.awt.Image down, java.awt.Image over)
public MHGUIButton(java.lang.String filenamebase)
The file names of the images are generated by appending the digits 0, 1, and 2 along with a .gif extension to the input parameter, and then loading an image file by that name. The 0 is for the image displayed in BUTTON_NORMAL state, the 1 is for the BUTTON_DOWN state, and 2 is for the BUTTON_OVER state.
filenamebase
- The base of the filename for loading
images.public MHGUIButton(java.lang.String filenamebase, java.lang.String imagetype)
filenamebase
- The base of the filename for loading
images.imagetype
- A string specifying the image file format
of the button image buttons.Method Detail |
---|
public java.lang.String getCaptionText()
public java.awt.Font getFont()
public void render(java.awt.Graphics2D g)
MHRenderable
g
- The Graphics object on which this object is to draw itself.public void setFont(java.awt.Font f)
public void setText(java.lang.String text)
public void setForeColor(java.awt.Color c)
public void mousePressed(java.awt.event.MouseEvent e)
mousePressed
in interface java.awt.event.MouseListener
mousePressed
in class MHGUIComponent
public void mouseReleased(java.awt.event.MouseEvent e)
mouseReleased
in interface java.awt.event.MouseListener
mouseReleased
in class MHGUIComponent
public void addActionListener(java.awt.event.ActionListener listener)
public void addKeyListener(java.awt.event.KeyListener listener)
public void addMouseListener(java.awt.event.MouseListener listener)
public void addMouseMotionListener(java.awt.event.MouseMotionListener listener)
public void advance()
MHRenderable
public void actionPerformed(java.awt.event.ActionEvent e)
actionPerformed
in interface java.awt.event.ActionListener
actionPerformed
in class MHGUIComponent
public void mouseClicked(java.awt.event.MouseEvent e)
mouseClicked
in interface java.awt.event.MouseListener
mouseClicked
in class MHGUIComponent
public void mouseMoved(java.awt.event.MouseEvent e)
mouseMoved
in class MHGUIComponent
public void keyPressed(java.awt.event.KeyEvent e)
keyPressed
in class MHGUIComponent
public void keyReleased(java.awt.event.KeyEvent e)
keyReleased
in class MHGUIComponent
public void keyTyped(java.awt.event.KeyEvent e)
keyTyped
in class MHGUIComponent
public java.awt.Color getDownColor()
public java.awt.Color getNormalColor()
public java.awt.Color getOverColor()
public void setDownColor(java.awt.Color downColor)
downColor
- The downColor to setpublic void setNormalColor(java.awt.Color normalColor)
normalColor
- The normalColor to setpublic void setOverColor(java.awt.Color overColor)
overColor
- The overColor to setpublic java.awt.Image getIcon()
public void setIcon(java.awt.Image icon)
icon
- The icon to setpublic int getType()
public void setType(int type)
type
- The type to setprotected java.awt.geom.Rectangle2D updateBounds()
updateBounds
in class MHGUIComponent
public void showBounds(boolean show)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |