|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectfds.micro.ui.Component
fds.micro.ui.TextField
This class implements a very basic text field.
An object of this class is dedicated to be used within an object of fds.micro.ui.AbstractPanel sub-class (J2ME).
Warning: DO NOT USE the class if you want a full featured text field. Due to some JVM implementations this class often support only capital letters and digits. It depends on the Canvas.keyPressed(int keyCode) method implementation. Check that before using ;-)
A text field have a label and an entry zone.
Within the entry zone you can enter characters at the position of a displayed cursor.
You can move the cursor with left and right arrows, or with a pointing device if it exist.
To delete the character just before the cursor (equivalent to a "backspace" action),
you must use the button mapped on your device with the FIRE game action.
No selection is supported.
You can read below a typical use within a class that inherit fds.micro.ui.RowPanel:
Construction
... this.field = new TextField(20, "My field label", "Default value"); // Maximum 20 characters long this.field.setBackground(192, 192, 192); // Light grey background this.field.setCursorColor(255, 0, 0); // Red cursor this.field.setTextColor(0, 0, 255); // Blue text in field entry zone this.append(this.field); ...Event handling
// 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 get the field content String content = this.field.getText(); ...
Field Summary | |
static int |
LABEL_LEFT
Specify that the label must be on the left of the field |
static int |
LABEL_TOP
Specify that the label must be on the top of the field |
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 | |
TextField()
Build an empty text field without label. |
|
TextField(int maxLength)
Build an empty text field without label. |
|
TextField(int maxLength,
java.lang.String label)
Build an empty text field with specified label. |
|
TextField(int maxLength,
java.lang.String label,
java.lang.String text)
Build a text field with specified label and initialized with given value. |
|
TextField(java.lang.String label)
Build an empty text field with specified label. |
|
TextField(java.lang.String label,
java.lang.String text)
Build a text field with specified label and initialized with given value. |
Method Summary | |
void |
addValueChangeListener(ValueChangeListener listener)
Add a listener object that will receive events produced by this component when the value is changed. |
int |
getCursorPosition()
Get the position of the cursor in field. |
java.lang.String |
getLabel()
Get the field label. |
javax.microedition.lcdui.Font |
getLabelFont()
Get the font used to display the field label. |
int |
getLabelPosition()
Get the position of the field label. |
int |
getLength()
Get the number of entered characters. |
java.lang.String |
getText()
Get the field value. |
javax.microedition.lcdui.Font |
getTextFont()
Get the font used to display the field value. |
boolean |
isBoxOpaque()
Get the entry zone opacity flag. |
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 |
removeValueChangListener(ValueChangeListener listener)
Remove a listener. |
void |
setBorderColor(int red,
int green,
int blue)
Set the color for field border. |
void |
setBoxOpaque(boolean boxOpaque)
Set a new value for entry zone opacity flag. |
void |
setCursorColor(int red,
int green,
int blue)
Set the color for field cursor. |
void |
setCursorPosition(int cursorPosition)
Change the position of the cursor in field. |
void |
setFieldBackground(int red,
int green,
int blue)
Set the color for field background. |
void |
setFieldBackgroundOff(int red,
int green,
int blue)
Set the color for field background if component is disabled. |
void |
setLabel(java.lang.String label)
Set the field label. |
void |
setLabelColor(int red,
int green,
int blue)
Set the label color. |
void |
setLabelFont(javax.microedition.lcdui.Font labelFont)
Change the font used to display the field label. |
void |
setLabelPosition(int labelPosition)
Change the position of the field label. |
void |
setMaximumSize(int width,
int height)
Set the maximum size for this component. |
void |
setText(java.lang.String text)
Set the field value. |
void |
setTextColor(int red,
int green,
int blue)
Set the field value color. |
void |
setTextColorOff(int red,
int green,
int blue)
Set the field value color if component is disabled. |
void |
setTextFont(javax.microedition.lcdui.Font textFont)
Change the font used to display the field value. |
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 |
Field Detail |
public static final int LABEL_LEFT
public static final int LABEL_TOP
Constructor Detail |
public TextField()
public TextField(int maxLength)
maxLength
- The maximum length for this field.public TextField(int maxLength, java.lang.String label)
maxLength
- The maximum length for this field.label
- Label to display before the field (null if no label).public TextField(int maxLength, java.lang.String label, java.lang.String text)
maxLength
- The maximum length for this field.label
- Label to display before the field (null if no label).text
- Initial field value.public TextField(java.lang.String label)
label
- Label to display before the field (null if no label).public TextField(java.lang.String label, java.lang.String text)
label
- Label to display before the field (null if no label).text
- Initial field value.Method Detail |
public void addValueChangeListener(ValueChangeListener listener)
listener
- The listener to add.public int getCursorPosition()
public java.lang.String getLabel()
public javax.microedition.lcdui.Font getLabelFont()
public int getLabelPosition()
public int getLength()
public java.lang.String getText()
public javax.microedition.lcdui.Font getTextFont()
public boolean isBoxOpaque()
public void keyPressed(int keyCode, int gameAction)
keyPressed
in class Component
keyCode
- The key code.gameAction
- Game action corresponding to the key code.public void pointerPressed(int xpos, int ypos)
pointerPressed
in class Component
xpos
- The X position of pointer on parent Canvas.ypos
- The Y position of pointer on parent Canvas.public void removeValueChangListener(ValueChangeListener listener)
listener
- The listener to remove.public void setBorderColor(int red, int green, int blue)
red
- The red component of the color.green
- The green component of the color.blue
- The blue component of the color.public void setBoxOpaque(boolean boxOpaque)
boxOpaque
- Must be true to paint background of entry zone, and false to not paint it.public void setCursorColor(int red, int green, int blue)
red
- The red component of the color.green
- The green component of the color.blue
- The blue component of the color.public void setCursorPosition(int cursorPosition)
cursorPosition
- The cursor position. Must be zero for the cursor to be on the left.public void setFieldBackground(int red, int green, int blue)
red
- The red component of the color.green
- The green component of the color.blue
- The blue component of the color.public void setFieldBackgroundOff(int red, int green, int blue)
red
- The red component of the color.green
- The green component of the color.blue
- The blue component of the color.public void setLabel(java.lang.String label)
label
- The label to set.public void setLabelColor(int red, int green, int blue)
red
- The red component of the color.green
- The green component of the color.blue
- The blue component of the color.public void setLabelFont(javax.microedition.lcdui.Font labelFont)
labelFont
- The label font to set.public void setLabelPosition(int labelPosition)
labelPosition
- The label position to set. Must be LABEL_LEFT or LABEL_TOP.public void setMaximumSize(int width, int height)
setMaximumSize
in class Component
width
- The maximum width.height
- The maximum height.public void setText(java.lang.String text)
text
- The new field value.public void setTextColor(int red, int green, int blue)
red
- The red component of the color.green
- The green component of the color.blue
- The blue component of the color.public void setTextColorOff(int red, int green, int blue)
red
- The red component of the color.green
- The green component of the color.blue
- The blue component of the color.public void setTextFont(javax.microedition.lcdui.Font textFont)
textFont
- The field value font to set.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |