fds.micro.ui
Class CheckBox

java.lang.Object
  extended byfds.micro.ui.Component
      extended byfds.micro.ui.CheckBox

public class CheckBox
extends Component

This class implements a check box with a label.
An object of this class is dedicated to be used within an object of fds.micro.ui.AbstractPanel sub-class (J2ME).
Warning: Use this class only if you want to have control on rendering. If possible, always prefer javax.microedition.lcdui.Item sub-classes.

You can read below a typical use within a class that inherit fds.micro.ui.RowPanel:

Construction

 ...
 this.checkBox = new CheckBox("My label", true); // Checked by default
 this.checkBox.setBoxColor(255, 255, 0); // Yellow box background
 this.checkBox.setMarkColor(255, 0, 0); // Red mark
 this.checkBox.setForeground(0, 0, 255); // Blue text
 this.append(this.checkBox);
 ...
 
Event handling modification
 // By default, events are handled. If you want to change some behaviour you can overwrite the following methods: 
 public void keyPressed(int keyCode) {
     if(keyCode == mySpecialCode) {
         ...
     }
     else {
         super.keyPressed(keyCode);
     }
 }
 public void pointerPressed(int x, int y) {
     if((x > myXmin) && (x < myXmax) && (y > myYmin) && (y < myYmax)) {
         ...
     }
     else {
         super.pointerPressed(x, y);
     }
 }
 
Usage
 ...
 // Here we want to know if the check box is selected
 if(this.checkBox.isChecked()) {
   // Do something
   ...
 }
 ...
 

Author:
Frédéric DE STEUR

Field Summary
 
Fields inherited from class fds.micro.ui.Component
INTERN_BOTTOM_VALIGN, INTERN_CENTER_HALIGN, INTERN_CENTER_VALIGN, INTERN_LEFT_HALIGN, INTERN_RIGHT_HALIGN, INTERN_TOP_VALIGN
 
Constructor Summary
CheckBox()
          Build a new CheckBox with no text and default attributes.
CheckBox(boolean checked)
          Build a new CheckBox with no text and default attributes.
CheckBox(java.lang.String text)
          Build a new CheckBox with given text and default attributes.
CheckBox(java.lang.String text, boolean checked)
          Build a new CheckBox with given text and default attributes.
 
Method Summary
 void addActionListener(ActionListener listener)
          Add a listener object that will receive action events produced by this component.
 void changeStatus()
          Change the check box status.
 java.lang.String getActionCommand()
          Get the command associated with the check box activation/deactivation.
 javax.microedition.lcdui.Font getFont()
          Get the font used to display the check box label.
 java.lang.String getText()
          Get the text displayed for this check box.
 boolean isBoxOpaque()
          Get the check box opacity flag for box background.
 boolean isChecked()
          Test if check box is selected.
 void keyPressed(int keyCode, int gameAction)
          Called to notify the component that a key is pressed.
 void pointerPressed(int xpos, int ypos)
          Called to notify the component that pointer device was pressed.
 void removeActionListener(ActionListener listener)
          Remove a listener.
 void setActionCommand(java.lang.String actionCommand)
          Set a command string that will be associated with the check box activation/deactivation.
 void setBoxBackground(int red, int green, int blue)
          Set the color used to draw the box background.
 void setBoxBackgroundOff(int red, int green, int blue)
          Set the color used to draw the box background if component is disabled.
 void setBoxColor(int red, int green, int blue)
          Set the color used to draw the box border.
 void setBoxOpaque(boolean boxOpaque)
          Set/reset the opacity flag for check box background.
 void setChecked(boolean checked)
          Change the selection status of the check box with a specific value.
 void setFont(javax.microedition.lcdui.Font font)
          Set the font to use for drawing text.
 void setForeground(int red, int green, int blue)
          Set the foreground color used to draw the check box (box and text).
 void setMarkColor(int red, int green, int blue)
          Set the color used to draw the mark if the box is checked.
 void setMaximumSize(int width, int height)
          Set the maximum size for this component.
 void setText(java.lang.String text)
          Set the font to use for drawing text.
 
Methods inherited from class fds.micro.ui.Component
addFocusListener, addItemListener, equals, getHAlign, getHeight, getParent, getVAlign, getWidth, getX, getY, isDisabled, isHaveFocus, isHidden, isManageFocus, isOpaque, removeFocusListener, removeItemListener, setBackground, setDisabled, setFocusColor, setHAlign, setHidden, setLocation, setManageFocus, setOpaque, setVAlign
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CheckBox

public CheckBox()
Build a new CheckBox with no text and default attributes.


CheckBox

public CheckBox(boolean checked)
Build a new CheckBox with no text and default attributes.

Parameters:
checked - Must be true to check to box.

CheckBox

public CheckBox(java.lang.String text)
Build a new CheckBox with given text and default attributes.

Parameters:
text - The text to display after the box.

CheckBox

public CheckBox(java.lang.String text,
                boolean checked)
Build a new CheckBox with given text and default attributes.

Parameters:
text - The text to display after the box.
checked - Must be true to check to box.
Method Detail

addActionListener

public void addActionListener(ActionListener listener)
Add a listener object that will receive action events produced by this component.

Parameters:
listener - The listener to add.

changeStatus

public void changeStatus()
Change the check box status. i.e. check if it was not, or uncheck if it was.


getActionCommand

public java.lang.String getActionCommand()
Get the command associated with the check box activation/deactivation.

Returns:
Returns the action command string.

getFont

public javax.microedition.lcdui.Font getFont()
Get the font used to display the check box label.

Returns:
The currently used font.

getText

public java.lang.String getText()
Get the text displayed for this check box.

Returns:
The check box label.

isBoxOpaque

public boolean isBoxOpaque()
Get the check box opacity flag for box background.

Returns:
Returns true if the box background is filled.

isChecked

public boolean isChecked()
Test if check box is selected.

Returns:
Returns true if the box is checked.

keyPressed

public void keyPressed(int keyCode,
                       int gameAction)
Called to notify the component that a key is pressed.

Specified by:
keyPressed in class Component
Parameters:
keyCode - The key code.
gameAction - Game action corresponding to the key code.

pointerPressed

public void pointerPressed(int xpos,
                           int ypos)
Called to notify the component that pointer device was pressed.

Specified by:
pointerPressed in class Component
Parameters:
xpos - The X position of pointer on parent Canvas.
ypos - The Y position of pointer on parent Canvas.

removeActionListener

public void removeActionListener(ActionListener listener)
Remove a listener.

Parameters:
listener - The listener to remove.

setActionCommand

public void setActionCommand(java.lang.String actionCommand)
Set a command string that will be associated with the check box activation/deactivation.

Parameters:
actionCommand - The action command to set.

setBoxBackground

public void setBoxBackground(int red,
                             int green,
                             int blue)
Set the color used to draw the box background.

Parameters:
red - The red component (0 to 255).
green - The green component (0 to 255).
blue - The blue component (0 to 255).

setBoxBackgroundOff

public void setBoxBackgroundOff(int red,
                                int green,
                                int blue)
Set the color used to draw the box background if component is disabled.

Parameters:
red - The red component (0 to 255).
green - The green component (0 to 255).
blue - The blue component (0 to 255).

setBoxColor

public void setBoxColor(int red,
                        int green,
                        int blue)
Set the color used to draw the box border.

Parameters:
red - The red component (0 to 255).
green - The green component (0 to 255).
blue - The blue component (0 to 255).

setBoxOpaque

public void setBoxOpaque(boolean boxOpaque)
Set/reset the opacity flag for check box background.

Parameters:
boxOpaque - Must be true to fill the box background.

setChecked

public void setChecked(boolean checked)
Change the selection status of the check box with a specific value.

Parameters:
checked - Must be true to check to box.

setFont

public void setFont(javax.microedition.lcdui.Font font)
Set the font to use for drawing text.

Parameters:
font - The new font to use.

setForeground

public void setForeground(int red,
                          int green,
                          int blue)
Set the foreground color used to draw the check box (box and text).

Parameters:
red - The red component (0 to 255).
green - The green component (0 to 255).
blue - The blue component (0 to 255).

setMarkColor

public void setMarkColor(int red,
                         int green,
                         int blue)
Set the color used to draw the mark if the box is checked.

Parameters:
red - The red component (0 to 255).
green - The green component (0 to 255).
blue - The blue component (0 to 255).

setMaximumSize

public void setMaximumSize(int width,
                           int height)
Set the maximum size for this component.

Overrides:
setMaximumSize in class Component
Parameters:
width - The maximum width.
height - The maximum height.

setText

public void setText(java.lang.String text)
Set the font to use for drawing text.

Parameters:
text - The new check box text.