fds.micro.ui
Class Button

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

public class Button
extends Component

This class implements a simple button without move effect when activated.
An object of this class is dedicated to be used within an object of fds.micro.ui.AbstractPanel sub-class (J2ME).

The button can be three kind:

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 simple use within a fds.micro.ui.RowPanel:

 ...
 // Build a panel
 RowPanel panel = new RowPanel();
 ...
 // Add a OK button 
 final Button okBut = new Button("Ok");
 okBut.setBackground(0, 128, 0); // Dark green
 okBut.setFocusColor(255, 255, 0); // Yellow
 okBut.addActionListener(
     new ActionListener() {
         public void actionPerformed(ActionEvent evt) {
             // Button activated
             ...
         }
     }
 );
 panel.append(okBut);
 ...
 

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
Button()
          Build the smallest possible button without text nor image.
Button(javax.microedition.lcdui.Image image)
          Build a button with an image inside.
Button(int width, int height)
          Build a button with given size without text or image.
Button(java.lang.String text)
          Build a button with a text inside.
 
Method Summary
 void activateButton()
          Activate the button.
 void addActionListener(ActionListener listener)
          Add a listener object that will receive action events produced by this component.
 java.lang.String getActionCommand()
          Get the command associated with the button activation.
 javax.microedition.lcdui.Image getImage()
          Get the image used to display the whole button.
 java.lang.String getText()
          Get the text displayed within the button.
 javax.microedition.lcdui.Font getTextFont()
          Get the font used to display the button text.
 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 button activation.
 void setBodyColor(int red, int green, int blue)
          Set the background body color (inside the button).
 void setButtonImage(javax.microedition.lcdui.Image image)
          Set the image used to display the whole button.
 void setExtBorderColor(int red, int green, int blue)
          Set the external border color.
 void setLowBorderColor(int red, int green, int blue)
          Set the internal border color for right and bottom.
 void setMaximumSize(int width, int height)
          Set the maximum size for this component.
 void setSize(int width, int height)
          Set the button size.
 void setText(java.lang.String text)
          Set the text displayed within the button.
 void setTextColor(int red, int green, int blue)
          Set the button text color.
 void setTextColorOff(int red, int green, int blue)
          Set the button text color used if the button is disabled.
 void setTextFont(javax.microedition.lcdui.Font textFont)
          Change the font used to display the button text.
 void setUpBorderColor(int red, int green, int blue)
          Set the internal border color for left and top.
 
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

Button

public Button()
Build the smallest possible button without text nor image.


Button

public Button(javax.microedition.lcdui.Image image)
Build a button with an image inside.

Parameters:
image - The image to display in the button

Button

public Button(int width,
              int height)
Build a button with given size without text or image.

Parameters:
width - The button width
height - The button height
Throws:
java.lang.IllegalArgumentException - if width or height is lower than 7 pixels (4 pixels for borders (2 x 2pixels) + 2 pixels for focus frame (2 x 1 pixel) + 1 pixel for body at center).

Button

public Button(java.lang.String text)
Build a button with a text inside.

Parameters:
text - The text to display in the button
Method Detail

activateButton

public void activateButton()
Activate the button.


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.

getActionCommand

public java.lang.String getActionCommand()
Get the command associated with the button activation.

Returns:
Returns the action command string.

getImage

public javax.microedition.lcdui.Image getImage()
Get the image used to display the whole button.

Returns:
Returns the button image.

getText

public java.lang.String getText()
Get the text displayed within the button.

Returns:
Returns the button text.

getTextFont

public javax.microedition.lcdui.Font getTextFont()
Get the font used to display the button text.

Returns:
Returns the text font.

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 button activation.

Parameters:
actionCommand - The action command to set.

setBodyColor

public void setBodyColor(int red,
                         int green,
                         int blue)
Set the background body color (inside the button).

Parameters:
red - The red component of the color to set.
green - The green component of the color to set.
blue - The blue component of the color to set.

setButtonImage

public void setButtonImage(javax.microedition.lcdui.Image image)
Set the image used to display the whole button.

Parameters:
image - The button image.

setExtBorderColor

public void setExtBorderColor(int red,
                              int green,
                              int blue)
Set the external border color.

Parameters:
red - The red component of the color to set.
green - The green component of the color to set.
blue - The blue component of the color to set.

setLowBorderColor

public void setLowBorderColor(int red,
                              int green,
                              int blue)
Set the internal border color for right and bottom.

Parameters:
red - The red component of the color to set.
green - The green component of the color to set.
blue - The blue component of the color to set.

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.

setSize

public void setSize(int width,
                    int height)
Set the button size.

Parameters:
width - The width in pixels (Cannot be < 7).
height - The height in pixels (Cannot be < 7).
Throws:
java.lang.IllegalArgumentException - if width or height < 7.

setText

public void setText(java.lang.String text)
Set the text displayed within the button.

Parameters:
text - the button text.

setTextColor

public void setTextColor(int red,
                         int green,
                         int blue)
Set the button text color.

Parameters:
red - The red component of the color to set.
green - The green component of the color to set.
blue - The blue component of the color to set.

setTextColorOff

public void setTextColorOff(int red,
                            int green,
                            int blue)
Set the button text color used if the button is disabled.

Parameters:
red - The red component of the color to set.
green - The green component of the color to set.
blue - The blue component of the color to set.

setTextFont

public void setTextFont(javax.microedition.lcdui.Font textFont)
Change the font used to display the button text.

Parameters:
textFont - The text font.

setUpBorderColor

public void setUpBorderColor(int red,
                             int green,
                             int blue)
Set the internal border color for left and top.

Parameters:
red - The red component of the color to set.
green - The green component of the color to set.
blue - The blue component of the color to set.