com.sun.lwuit
Class Button

java.lang.Object
  extended by com.sun.lwuit.Component
      extended by com.sun.lwuit.Label
          extended by com.sun.lwuit.Button
Direct Known Subclasses:
CheckBox, RadioButton

public class Button
extends Label

Button is the base class for several UI widgets allowing clickability. It has 3 states: rollover, pressed and the default state it can also have ActionListeners that react when the Button is clicked.

Author:
Chen Fishbein

Field Summary
static int STATE_DEFAULT
          Indicates the default state of a button which is neither pressed nor focused
static int STATE_PRESSED
          Indicates the pressed state of a button
static int STATE_ROLLOVER
          Indicates the rollover state of a button which is equivalent to focused for most uses
 
Fields inherited from class com.sun.lwuit.Component
BOTTOM, BRB_CENTER_OFFSET, BRB_CONSTANT_ASCENT, BRB_CONSTANT_DESCENT, BRB_OTHER, CENTER, LEFT, RIGHT, TOP
 
Constructor Summary
Button()
          Constructs a button with an empty string for its text.
Button(Command cmd)
          Allows binding a command to a button for ease of use
Button(java.lang.String text)
          Constructs a button with the specified text.
Button(java.lang.String text, Image icon)
          Constructor a button with text and image
 
Method Summary
 void addActionListener(ActionListener l)
          Adds a listener to the button which will cause an event to dispatch on click
 boolean animate()
           
 Command getCommand()
          This method return the Button Command if exists
 Image getDisabledIcon()
          Indicates the icon that is displayed on the button when the button is in the disabled state
 Image getIconFromState()
          Returns the icon for the button based on its current state
 Image getPressedIcon()
          Indicates the icon that is displayed on the button when the button is in pressed state
 Image getRolloverIcon()
          Indicates the icon that is displayed on the button when the button is in rolled over state
 Image getRolloverPressedIcon()
          Indicates the icon that is displayed on the button when the button is in pressed state and is selected.
 int getState()
          Returns the button state
 boolean isOppositeSide()
          Places the check box or radio button on the opposite side at the far end
 boolean isSelected()
          Returns true if the button is selected for toggle buttons, throws an exception if this is not a toggle button
 boolean isToggle()
          Toggle button mode is only relevant for checkboxes/radio buttons.
 void keyPressed(int keyCode)
          If this Component is focused, the key pressed event will call this method
 void keyReleased(int keyCode)
          If this Component is focused, the key released event will call this method
 void keyRepeated(int keyCode)
          If this Component is focused, the key repeat event will call this method.
 void paint(Graphics g)
          This method paints the Component on the screen, it should be overriden by subclasses to perform custom drawing or invoke the UI API's to let the PLAF perform the rendering.
 void pointerDragged(int x, int y)
          If this Component is focused, the pointer dragged event will call this method
 void pointerHover(int[] x, int[] y)
          Invoked for devices where the pointer can hover without actually clicking the display.
 void pointerHoverReleased(int[] x, int[] y)
          Invoked for devices where the pointer can hover without actually clicking the display.
 void pointerPressed(int x, int y)
          If this Component is focused, the pointer pressed event will call this method
 void pointerReleased(int x, int y)
          If this Component is focused, the pointer released event will call this method
 void pressed()
          Invoked to change the state of the button to the pressed state
 void released()
          Invoked to change the state of the button to the released state
 void released(int x, int y)
          Invoked to change the state of the button to the released state
 void removeActionListener(ActionListener l)
          Removes the given action listener from the button
 void resetState()
          This method is an ugly hack to allow one to reset the button's state from the outside.
 void setAlignment(int align)
          Deprecated. use the Style alignment instead
 void setCommand(Command cmd)
          Applies the given command to this button
 void setDisabledIcon(Image disabledIcon)
          Indicates the icon that is displayed on the button when the button is in the disabled state
 void setPressedIcon(Image pressedIcon)
          Indicates the icon that is displayed on the button when the button is in pressed state
 void setRolloverIcon(Image rolloverIcon)
          Indicates the icon that is displayed on the button when the button is in rolled over state
 void setRolloverPressedIcon(Image rolloverPressedIcon)
          Indicates the icon that is displayed on the button when the button is in pressed state and is selected.
 void setToggle(boolean toggle)
          Toggle button mode is only relevant for checkboxes/radio buttons.
 
Methods inherited from class com.sun.lwuit.Label
getAlignment, getBaselineResizeBehavior, getGap, getIcon, getShiftText, getText, getTextPosition, getVerticalAlignment, isEndsWith3Points, isTickerEnabled, isTickerRunning, setEndsWith3Points, setGap, setIcon, setShiftText, setSize, setText, setTextPosition, setTickerEnabled, setVerticalAlignment, setWidth, shouldTickerStart, startTicker, startTicker, stopTicker
 
Methods inherited from class com.sun.lwuit.Component
addFocusListener, contains, drop, getAbsoluteX, getAbsoluteY, getBaseline, getBottomGap, getClientProperty, getComponentForm, getDirtyRegion, getDisabledStyle, getHeight, getLabelForComponent, getName, getNextFocusDown, getNextFocusLeft, getNextFocusRight, getNextFocusUp, getParent, getPreferredH, getPreferredSize, getPreferredW, getPressedStyle, getPropertyNames, getPropertyTypes, getPropertyValue, getScrollAnimationSpeed, getScrollDimension, getScrollOpacity, getScrollOpacityChangeSpeed, getScrollX, getScrollY, getSelectCommandText, getSelectedRect, getSelectedStyle, getSideGap, getStyle, getTensileLength, getUIID, getUnselectedStyle, getWidth, getX, getY, growShrink, handlesInput, hasFocus, isAlwaysTensile, isDraggable, isDropTarget, isEnabled, isFlatten, isFocusable, isGrabsPointerEvents, isHideInPortrait, isRTL, isScrollableX, isScrollableY, isScrollVisible, isSmoothScrolling, isSnapToGrid, isTactileTouch, isTensileDragEnabled, isVisible, paintBackgrounds, paintComponent, paintComponent, paintLock, paintLockRelease, pointerDragged, pointerHoverPressed, pointerPressed, pointerReleased, putClientProperty, refreshTheme, removeFocusListener, repaint, repaint, requestFocus, scrollRectToVisible, setAlwaysTensile, setCellRenderer, setDirtyRegion, setDisabledStyle, setDraggable, setDropTarget, setEnabled, setFlatten, setFocus, setFocusable, setGrabsPointerEvents, setHandlesInput, setHeight, setHideInPortrait, setIsScrollVisible, setLabelForComponent, setName, setNextFocusDown, setNextFocusLeft, setNextFocusRight, setNextFocusUp, setPreferredH, setPreferredSize, setPreferredW, setPressedStyle, setPropertyValue, setRTL, setScrollAnimationSpeed, setScrollOpacityChangeSpeed, setScrollSize, setScrollVisible, setSelectCommandText, setSelectedStyle, setShouldCalcPreferredSize, setSmoothScrolling, setSnapToGrid, setTactileTouch, setTensileDragEnabled, setTensileLength, setUIID, setUnselectedStyle, setVisible, setX, setY, styleChanged, toString
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

STATE_ROLLOVER

public static final int STATE_ROLLOVER
Indicates the rollover state of a button which is equivalent to focused for most uses

See Also:
Constant Field Values

STATE_PRESSED

public static final int STATE_PRESSED
Indicates the pressed state of a button

See Also:
Constant Field Values

STATE_DEFAULT

public static final int STATE_DEFAULT
Indicates the default state of a button which is neither pressed nor focused

See Also:
Constant Field Values
Constructor Detail

Button

public Button()
Constructs a button with an empty string for its text.


Button

public Button(java.lang.String text)
Constructs a button with the specified text.

Parameters:
text - label appearing on the button

Button

public Button(Command cmd)
Allows binding a command to a button for ease of use

Parameters:
cmd - command whose text would be used for the button and would recive action events from the button

Button

public Button(java.lang.String text,
              Image icon)
Constructor a button with text and image

Parameters:
text - label appearing on the button
icon - image appearing on the button
Method Detail

setCommand

public void setCommand(Command cmd)
Applies the given command to this button

Parameters:
cmd - the command on the button

getState

public int getState()
Returns the button state

Returns:
One of STATE_ROLLOVER, STATE_DEAFULT, STATE_PRESSED

getPressedIcon

public Image getPressedIcon()
Indicates the icon that is displayed on the button when the button is in pressed state

Returns:
icon used
See Also:
STATE_PRESSED

getRolloverPressedIcon

public Image getRolloverPressedIcon()
Indicates the icon that is displayed on the button when the button is in pressed state and is selected. This is ONLY applicable to toggle buttons

Returns:
icon used

setRolloverPressedIcon

public void setRolloverPressedIcon(Image rolloverPressedIcon)
Indicates the icon that is displayed on the button when the button is in pressed state and is selected. This is ONLY applicable to toggle buttons

Parameters:
rolloverPressedIcon - icon used

getDisabledIcon

public Image getDisabledIcon()
Indicates the icon that is displayed on the button when the button is in the disabled state

Returns:
icon used

getRolloverIcon

public Image getRolloverIcon()
Indicates the icon that is displayed on the button when the button is in rolled over state

Returns:
icon used
See Also:
STATE_ROLLOVER

setRolloverIcon

public void setRolloverIcon(Image rolloverIcon)
Indicates the icon that is displayed on the button when the button is in rolled over state

Parameters:
rolloverIcon - icon to use
See Also:
STATE_ROLLOVER

setPressedIcon

public void setPressedIcon(Image pressedIcon)
Indicates the icon that is displayed on the button when the button is in pressed state

Parameters:
pressedIcon - icon used
See Also:
STATE_PRESSED

setDisabledIcon

public void setDisabledIcon(Image disabledIcon)
Indicates the icon that is displayed on the button when the button is in the disabled state

Parameters:
disabledIcon - icon used

addActionListener

public void addActionListener(ActionListener l)
Adds a listener to the button which will cause an event to dispatch on click

Parameters:
l - implementation of the action listener interface

removeActionListener

public void removeActionListener(ActionListener l)
Removes the given action listener from the button

Parameters:
l - implementation of the action listener interface

getIconFromState

public Image getIconFromState()
Returns the icon for the button based on its current state

Returns:
the button icon based on its current state

pressed

public void pressed()
Invoked to change the state of the button to the pressed state


released

public void released()
Invoked to change the state of the button to the released state


released

public void released(int x,
                     int y)
Invoked to change the state of the button to the released state

Parameters:
x - the x position if a touch event triggered this, -1 if this isn't relevant
y - the y position if a touch event triggered this, -1 if this isn't relevant

keyPressed

public void keyPressed(int keyCode)
Description copied from class: Component
If this Component is focused, the key pressed event will call this method

Overrides:
keyPressed in class Component
Parameters:
keyCode - the key code value to indicate a physical key.

keyReleased

public void keyReleased(int keyCode)
Description copied from class: Component
If this Component is focused, the key released event will call this method

Overrides:
keyReleased in class Component
Parameters:
keyCode - the key code value to indicate a physical key.

keyRepeated

public void keyRepeated(int keyCode)
Description copied from class: Component
If this Component is focused, the key repeat event will call this method.

Overrides:
keyRepeated in class Component
Parameters:
keyCode - the key code value to indicate a physical key.

pointerHover

public void pointerHover(int[] x,
                         int[] y)
Description copied from class: Component
Invoked for devices where the pointer can hover without actually clicking the display. This is true for PC mouse pointer as well as some devices such as the BB storm.

Overrides:
pointerHover in class Component
Parameters:
x - the pointer x coordinate
y - the pointer y coordinate

pointerHoverReleased

public void pointerHoverReleased(int[] x,
                                 int[] y)
Description copied from class: Component
Invoked for devices where the pointer can hover without actually clicking the display. This is true for PC mouse pointer as well as some devices such as the BB storm.

Overrides:
pointerHoverReleased in class Component
Parameters:
x - the pointer x coordinate
y - the pointer y coordinate

pointerPressed

public void pointerPressed(int x,
                           int y)
Description copied from class: Component
If this Component is focused, the pointer pressed event will call this method

Overrides:
pointerPressed in class Component
Parameters:
x - the pointer x coordinate
y - the pointer y coordinate

pointerReleased

public void pointerReleased(int x,
                            int y)
Description copied from class: Component
If this Component is focused, the pointer released event will call this method

Overrides:
pointerReleased in class Component
Parameters:
x - the pointer x coordinate
y - the pointer y coordinate

pointerDragged

public void pointerDragged(int x,
                           int y)
Description copied from class: Component
If this Component is focused, the pointer dragged event will call this method

Overrides:
pointerDragged in class Component
Parameters:
x - the pointer x coordinate
y - the pointer y coordinate

paint

public void paint(Graphics g)
Description copied from class: Component
This method paints the Component on the screen, it should be overriden by subclasses to perform custom drawing or invoke the UI API's to let the PLAF perform the rendering.

Overrides:
paint in class Label
Parameters:
g - the component graphics

getCommand

public Command getCommand()
This method return the Button Command if exists

Returns:
Command Object or null if a Command not exists

isSelected

public boolean isSelected()
Returns true if the button is selected for toggle buttons, throws an exception if this is not a toggle button

Returns:
true if the button is selected

setAlignment

public void setAlignment(int align)
Deprecated. use the Style alignment instead

Description copied from class: Label
Sets the Alignment of the Label to one of: CENTER, LEFT, RIGHT

Overrides:
setAlignment in class Label
Parameters:
align - alignment value
See Also:
Component.CENTER, Component.LEFT, Component.RIGHT

isToggle

public boolean isToggle()
Toggle button mode is only relevant for checkboxes/radio buttons. When pressed a toggle button stays pressed and when pressed again it moves to releleased state.

Returns:
the toggle

setToggle

public void setToggle(boolean toggle)
Toggle button mode is only relevant for checkboxes/radio buttons. When pressed a toggle button stays pressed and when pressed again it moves to releleased state. Setting toggle implicitly changes the UIID to "ToggleButton"

Parameters:
toggle - the toggle to set

animate

public boolean animate()
Overrides:
animate in class Label

isOppositeSide

public boolean isOppositeSide()
Places the check box or radio button on the opposite side at the far end

Returns:
the oppositeSide

resetState

public void resetState()
This method is an ugly hack to allow one to reset the button's state from the outside. The practical use case for this is to allow a button to be brought back from the pressed state without triggering its action when the finger is dragged away from the button.