org.j4me.ui.components
Class CheckBox

java.lang.Object
  extended by org.j4me.ui.components.Component
      extended by org.j4me.ui.components.CheckBox

public class CheckBox
extends Component

The CheckBox component lets a user turn an option on or off. Multiple check box components can be placed sequentially to create a list of choices where zero or more can be chosen.


Field Summary
 
Fields inherited from class org.j4me.ui.components.Component
container, HIGHLIGHTED_BORDER_WIDTH
 
Constructor Summary
CheckBox()
          Constructs a CheckBox component.
 
Method Summary
 boolean acceptsInput()
          Tells if this component accepts user input or not.
 java.lang.String getLabel()
          Gets the value of the text that appears to the right of the check box.
protected  int[] getPreferredComponentSize(Theme theme, int viewportWidth, int viewportHeight)
          Returns the dimensions of the check box.
protected  void hideNotify()
          An event raised whenever the component is removed from the screen.
 boolean isChecked()
          Returns true if the box is checked or false if it is not.
 void keyPressed(int keyCode)
          Called when a key is pressed.
protected  void paintComponent(javax.microedition.lcdui.Graphics g, Theme theme, int width, int height, boolean selected)
          Paints the check box component.
 void pointerPressed(int x, int y)
          Called when the pointer is pressed.
 void setChecked(boolean checked)
          Checks or unchecks the box.
 void setLabel(java.lang.String value)
          Sets the text that appears next to the check box.
protected  void showNotify()
          An event raised whenever the component is made visible on the screen.
 
Methods inherited from class org.j4me.ui.components.Component
getHeight, getHorizontalAlignment, getPreferredSize, getScreen, getWidth, getX, getY, invalidate, isShown, keyReleased, keyRepeated, paint, paintRect, pointerDragged, pointerReleased, repaint, setHorizontalAlignment, visible
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CheckBox

public CheckBox()
Constructs a CheckBox component.

Method Detail

getLabel

public java.lang.String getLabel()
Gets the value of the text that appears to the right of the check box.

Returns:
The text that appears next to the check box. It will never be null but may be the empty string "".

setLabel

public void setLabel(java.lang.String value)
Sets the text that appears next to the check box.

Parameters:
value - is the text that appears to the right of the check box. A null is treated as the empty string "".

isChecked

public boolean isChecked()
Returns true if the box is checked or false if it is not.

Returns:
true if the box is checked or false if it is not.

setChecked

public void setChecked(boolean checked)
Checks or unchecks the box.

Parameters:
checked - when true checks the box; when false unchecks it.

showNotify

protected void showNotify()
An event raised whenever the component is made visible on the screen. This is called before the paintComponent method.

Overrides:
showNotify in class Component

hideNotify

protected void hideNotify()
An event raised whenever the component is removed from the screen.

Overrides:
hideNotify in class Component

paintComponent

protected void paintComponent(javax.microedition.lcdui.Graphics g,
                              Theme theme,
                              int width,
                              int height,
                              boolean selected)
Paints the check box component.

Specified by:
paintComponent in class Component
Parameters:
g - is the Graphics object to be used for rendering the item.
theme - is the application's theme. Use it to get fonts and colors.
width - is the width, in pixels, to paint the component.
height - is the height, in pixels, to paint the component.
selected - is true when this components is currently selected and false when it is not.
See Also:
Component.paintComponent(javax.microedition.lcdui.Graphics, org.j4me.ui.Theme, int, int, boolean)

getPreferredComponentSize

protected int[] getPreferredComponentSize(Theme theme,
                                          int viewportWidth,
                                          int viewportHeight)
Returns the dimensions of the check box.

Specified by:
getPreferredComponentSize in class Component
Parameters:
theme - is the application's Theme.
viewportWidth - is the width of the viewable area, in pixels, the component can use.
viewportHeight - is the height of the viewable area, in pixels, the component can use.
Returns:
A array with two elements where the first is the width of the component in pixels and the second is the height.
See Also:
Component.getPreferredComponentSize(org.j4me.ui.Theme, int, int)

acceptsInput

public boolean acceptsInput()
Description copied from class: Component
Tells if this component accepts user input or not. If it does then it can be scrolled to by the user. If it does not, it will be displayed, but can be skipped over by scrolling.

The default implementation returns false. Override this method to return true if the component accepts input.

Overrides:
acceptsInput in class Component
Returns:
true because this component accepts user input.

keyPressed

public void keyPressed(int keyCode)
Called when a key is pressed.

Overrides:
keyPressed in class Component
Parameters:
keyCode - is the key code of the key that was pressed.

pointerPressed

public void pointerPressed(int x,
                           int y)
Called when the pointer is pressed.

Overrides:
pointerPressed in class Component
Parameters:
x - is the horizontal location where the pointer was pressed relative to the top-left corner of the component.
y - is the vertical location where the pointer was pressed relative to the top-left corner of the component.