All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class tea.set.ImageButton

java.lang.Object
   |
   +----java.awt.Component
           |
           +----java.awt.Canvas
                   |
                   +----tea.set.ImageButton

public class ImageButton
extends Canvas
ImageButton is a widget that behaves like a regular button. But instead of displaying a text label, it displays an image inside the button. An ImageButton can be simply constructed by supplying a plain image. A 3D button image will automatically generated. The default size of the button is the size of the image. If the button is resized to a size other than the image size, the image is scaled to the new button size.

An optional label can be specified for the button. If a label is specified, it will be show together with the image. A second image can be supplied for displaying when the button is in pressed mode. This is normally used when the button is in toggle mode.

ImageButton supports the following properties:
Property NameProperty TypeDescription
Toggleboolean Toggle button mode flag.
Stateboolean Toggle button state.
LabelString Button text label.
Displayint Button display style, IMAGE_ONLY, LABEL_ONLY, or LABEL_IMAGE.
PreferredSizeDimension Button preferred size. Can be set to override the calculated size.
LabelPosint Button label position flag.
ImageImage Button image.
Image2Image2 Button pressed image.

ImageButton generates the following events:
Event TypeEvent IDGenerated Description
ActionEventActionEvent.ACTION_PERFORMED Button pressed, or state changed if toggle button. ActionEvent.getActionCommand() contains the button label.


Variable Index

 o BOTTOM
BOTTOM specifies the label of the button being placed at the bottom of the button.
 o eventMgr
EventMgr object handles added event processing and dispatching.
 o IMAGE_ONLY
Display button image only.
 o LABEL_IMAGE
Display button image and label.
 o LABEL_ONLY
Display button text label only.
 o LEFT
LEFT specifies the label of the button being placed at the left of the button.
 o RIGHT
RIGHT specifies the label of the button being placed at the right of the button.
 o TOP
TOP specifies the label of the button being placed at the top of the button.

Constructor Index

 o ImageButton()
Construct an ImageButton with no image.
 o ImageButton(Image)
Contruct an ImageButton with the supplied image.
 o ImageButton(Image, String)
Construct an ImageButton with image and a label.
 o ImageButton(Image, String, int)
Construct an ImageButton with image and a label.

Method Index

 o addActionListener(ActionListener)
Add an action listener.
 o getDisplay()
Get the display style.
 o getImage()
Get the button image.
 o getImage2()
Get the button pressed image.
 o getLabel()
Return the label of the button, null if none.
 o getLabelPos()
Get the button label position.
 o getMinimumSize()
Return the minimum size of the button.
 o getPreferredSize()
Return the preferred size of the button.
 o getState()
Get the current toggle state.
 o isToggle()
Get the toggle mode.
 o paint(Graphics)
Paint button.
 o processActionEvent(ActionEvent)
Process and dispatch action event.
 o processEvent(AWTEvent)
Process and dispatch event.
 o processMouseEvent(MouseEvent)
Mouse down event causes a pressed button image to be shown.
 o removeActionListener(ActionListener)
Remove an action listener.
 o setBackground(Color)
Set the background color.
 o setDisplay(int)
Set the button display style, IMAGE_ONLY, LABEL_ONLY, or LABEL_IMAGE.
 o setEnabled(boolean)
Enable the button.
 o setFont(Font)
Set the font.
 o setForeground(Color)
Set the foreground color.
 o setImage(Image)
Set or change the image displayed by this button.
 o setImage2(Image)
Set or change the image displayed by this button for pressed mode.
 o setLabel(String)
Set the label for this button.
 o setLabel(String, int)
Set the label for this button.
 o setLabelPos(int)
Set the label position.
 o setPreferredSize(Dimension)
Change the size of the button to dimension.
 o setState(boolean)
Set the toggle button state.
 o setToggle(boolean)
If toggle mode is true, the button behaves as a toggle button (checkbox).

Variables

 o LABEL_ONLY
 public static final int LABEL_ONLY
Display button text label only.

 o IMAGE_ONLY
 public static final int IMAGE_ONLY
Display button image only.

 o LABEL_IMAGE
 public static final int LABEL_IMAGE
Display button image and label.

 o TOP
 public static final int TOP
TOP specifies the label of the button being placed at the top of the button.

 o LEFT
 public static final int LEFT
LEFT specifies the label of the button being placed at the left of the button.

 o BOTTOM
 public static final int BOTTOM
BOTTOM specifies the label of the button being placed at the bottom of the button.

 o RIGHT
 public static final int RIGHT
RIGHT specifies the label of the button being placed at the right of the button.

 o eventMgr
 protected EventMgr eventMgr
EventMgr object handles added event processing and dispatching.

Constructors

 o ImageButton
 public ImageButton()
Construct an ImageButton with no image. ImageButton.setImage() must be called before this component can be used.

 o ImageButton
 public ImageButton(Image iv)
Contruct an ImageButton with the supplied image.

Parameters:
iv - button image.
 o ImageButton
 public ImageButton(Image iv,
                    String label)
Construct an ImageButton with image and a label. The default label position is below the image.

Parameters:
iv - button image.
label - button label.
 o ImageButton
 public ImageButton(Image iv,
                    String label,
                    int pos)
Construct an ImageButton with image and a label. A position for the label can be specified.

Parameters:
iv - button image.
label - button label.
pos - label position flag.

Methods

 o setToggle
 public synchronized void setToggle(boolean f)
If toggle mode is true, the button behaves as a toggle button (checkbox). Otherwise it behaves as a regular button.

Parameters:
f - toggle mode.
 o isToggle
 public boolean isToggle()
Get the toggle mode.

Returns:
toggle mode.
 o setState
 public synchronized void setState(boolean f)
Set the toggle button state. This is only used when button is in toggle mode.

Parameters:
f - toggle state.
 o getState
 public boolean getState()
Get the current toggle state.

Returns:
toggle state.
 o setLabel
 public synchronized void setLabel(String label,
                                   int pos)
Set the label for this button. If there was no label, the apperance of the button is going to change. The size of the button may also change depending of the label and image.

Parameters:
label - button label.
pos - label position flag.
 o setLabel
 public void setLabel(String label)
Set the label for this button. If there was no label, the apperance of the button is going to change. The size of the button may also change depending of the label and image.

Parameters:
label - button label.
 o getLabel
 public String getLabel()
Return the label of the button, null if none.

Returns:
button label.
 o setLabelPos
 public void setLabelPos(int pos)
Set the label position.

Parameters:
pos - label position flag.
 o getLabelPos
 public int getLabelPos()
Get the button label position.

Returns:
label position.
 o setDisplay
 public synchronized void setDisplay(int style)
Set the button display style, IMAGE_ONLY, LABEL_ONLY, or LABEL_IMAGE.

Parameters:
style - display style.
 o getDisplay
 public int getDisplay()
Get the display style.

Returns:
display style.
 o setEnabled
 public void setEnabled(boolean f)
Enable the button.

Overrides:
setEnabled in class Component
 o setPreferredSize
 public void setPreferredSize(Dimension s)
Change the size of the button to dimension.

Parameters:
s - button dimension.
 o getMinimumSize
 public Dimension getMinimumSize()
Return the minimum size of the button.

Returns:
minimum size.
Overrides:
getMinimumSize in class Component
 o getPreferredSize
 public Dimension getPreferredSize()
Return the preferred size of the button.

Returns:
preferred size.
Overrides:
getPreferredSize in class Component
 o setImage
 public synchronized void setImage(Image iv)
Set or change the image displayed by this button.

Parameters:
iv - button image.
 o getImage
 public Image getImage()
Get the button image. This image is not filtered so it does not have a button border.

Returns:
button image.
 o setImage2
 public synchronized void setImage2(Image iv)
Set or change the image displayed by this button for pressed mode.

Parameters:
iv - button image.
 o getImage2
 public Image getImage2()
Get the button pressed image. This image is not filtered so it does not have a button border.

Returns:
button image.
 o setForeground
 public void setForeground(Color c)
Set the foreground color.

Parameters:
c - foreground color.
Overrides:
setForeground in class Component
 o setBackground
 public void setBackground(Color c)
Set the background color.

Parameters:
c - background color.
Overrides:
setBackground in class Component
 o setFont
 public void setFont(Font f)
Set the font.

Parameters:
f - font.
Overrides:
setFont in class Component
 o addActionListener
 public void addActionListener(ActionListener listener)
Add an action listener.

Parameters:
listener - action listener.
 o removeActionListener
 public void removeActionListener(ActionListener listener)
Remove an action listener.

Parameters:
listener - action listener.
 o processEvent
 public void processEvent(AWTEvent e)
Process and dispatch event.

Parameters:
e - event object.
Overrides:
processEvent in class Component
 o processActionEvent
 public void processActionEvent(ActionEvent e)
Process and dispatch action event.

Parameters:
e - action event.
 o paint
 public void paint(Graphics g)
Paint button.

Parameters:
g - Graphics context of this component.
Overrides:
paint in class Canvas
 o processMouseEvent
 public void processMouseEvent(MouseEvent e)
Mouse down event causes a pressed button image to be shown. Mouse exit event causes a button to change back to normal state. Mouse up event generates an action event.

Parameters:
e - event object.
Overrides:
processMouseEvent in class Component

All Packages  Class Hierarchy  This Package  Previous  Next  Index