org.j4me.ui.components
Class TextBox

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

public class TextBox
extends Component

A TextBox is a component for entering text, numbers, and keyboard data. It equivalent to the javax.microedition.lcdui.TextField class.

This component is not yet complete. Features that still need to be added include:

See Also:
TextField

Field Summary
 
Fields inherited from class org.j4me.ui.components.Component
container, HIGHLIGHTED_BORDER_WIDTH
 
Constructor Summary
TextBox()
          Creates a new TextBox component.
 
Method Summary
 boolean acceptsInput()
          Tells if this component accepts user input or not.
 java.lang.String getLabel()
           
 int getMaxSize()
          Returns the maximum size (number of characters) that can be stored in this TextBox.
protected  int[] getPreferredComponentSize(Theme theme, int viewportWidth, int viewportHeight)
          Returns the dimensions of the text box.
 java.lang.String getString()
          Gets the contents of the TextBox as a string value.
protected  void hideNotify()
          An event raised whenever the component is removed from the screen.
 boolean isPassword()
          Returns if this text box is for sensitive data or not.
 boolean isPhoneNumber()
           
 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 text box.
 void pointerPressed(int x, int y)
          Called when the pointer is pressed.
protected  void select()
          Called when the text box's value is being edited.
 void setForAnyText()
          Allows any text to be entered including letters, numbers, punctuation, and newlines.
 void setForNumericOnly()
          Allows only integer values to be input.
 void setForPhoneNumber()
          Allows for entering a phone number.
 void setLabel(java.lang.String label)
           
 void setMaxSize(int maxSize)
          Sets the maximum size (number of characters) that can be contained in this TextBox.
 void setPassword(boolean password)
          Sets if this text box is for sensitive data or not.
 void setString(java.lang.String text)
          Sets the contents of the TextBox as a string value, replacing the previous contents.
protected  void showNotify()
          An event raised whenever the component is made visible on the screen.
 int size()
          Gets the number of characters that are currently stored in this TextBox.
 
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

TextBox

public TextBox()
Creates a new TextBox component.

Method Detail

getLabel

public java.lang.String getLabel()
Returns:
The text that appears above the text box. If null there is no text.

setLabel

public void setLabel(java.lang.String label)
Parameters:
label - is the text that appears above the text box. If null there will be no text.

getString

public java.lang.String getString()
Gets the contents of the TextBox as a string value.

Returns:
The current contents or null if there is no data.
See Also:
setString(String)

setString

public void setString(java.lang.String text)
Sets the contents of the TextBox as a string value, replacing the previous contents.

Parameters:
text - is the new value of the TextBox, or null if the TextBox is to be made empty.
Throws:
java.lang.IllegalArgumentException - if text is illegal for the current input constraints.
java.lang.IllegalArgumentException - if text would exceed the current maximum capacity.
See Also:
getString()

setForAnyText

public void setForAnyText()
Allows any text to be entered including letters, numbers, punctuation, and newlines.


setForNumericOnly

public void setForNumericOnly()
Allows only integer values to be input.


setForPhoneNumber

public void setForPhoneNumber()
Allows for entering a phone number.


isPhoneNumber

public boolean isPhoneNumber()
Returns:
true if this text box is for entering a phone number; false otherwise.

setPassword

public void setPassword(boolean password)
Sets if this text box is for sensitive data or not. Sensitive data is displayed as '*' characters.

The default is for non-sensitive data.

Parameters:
password - is true if this text box contains a password; false otherwise.

isPassword

public boolean isPassword()
Returns if this text box is for sensitive data or not.

The default is for non-sensitive data.

Returns:
true if this text box contains a password; false otherwise.

getMaxSize

public int getMaxSize()
Returns the maximum size (number of characters) that can be stored in this TextBox.

Returns:
The maximum size in characters.
See Also:
setMaxSize(int)

setMaxSize

public void setMaxSize(int maxSize)
Sets the maximum size (number of characters) that can be contained in this TextBox. If the current contents of the TextBox are larger than maxSize, the contents are truncated to fit.

Parameters:
maxSize - is the new maximum size. It must be 1 or more.

size

public int size()
Gets the number of characters that are currently stored in this TextBox.

Returns:
The number of characters in the TextBox.

paintComponent

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

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(Graphics, Theme, int, int, boolean)

getPreferredComponentSize

protected int[] getPreferredComponentSize(Theme theme,
                                          int viewportWidth,
                                          int viewportHeight)
Returns the dimensions of the text 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)

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
See Also:
Component.showNotify()

hideNotify

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

Overrides:
hideNotify in class Component
See Also:
Component.hideNotify()

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.

select

protected void select()
Called when the text box's value is being edited. This method replaces the current screen with the JVM's TextBox screen. When the user enters a new value the original screen returns and is updated with the new value.