|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--javax.microedition.lcdui.Item | +--javax.microedition.lcdui.TextField
A TextField is an editable text component that may be placed into a
Form
. It can be given a piece of text that is used as
the initial value.
A TextField has a maximum size, which is the maximum number of characters that can be stored in the object at any time (its capacity). This limit is enforced when the user is editing text within the TextField, as well as when the application program calls methods on the TextField that modify its contents. The maximum size is the maximum stored capacity and is unrelated to the number of characters that may be displayed at any given time. The number of characters displayed and their arrangement into rows and columns are determined by the device.
The implementation may place a boundary on the maximum size, and the maximum
size actually assigned may be smaller than the application requested.
The value actually assigned will be reflected in the value returned by
getMaxSize()
. A defensively-written application should
compare this value to the maximum size requested and be prepared to handle
cases where they differ.
Input Constraints
The TextField shares the concept of input constraints with the
TextBox
object. The different constraints allow the
application to request that the user's input be restricted in a
variety of ways. The implementation is required to restrict the
user's input as requested by the application. For example, if the
application requests the NUMERIC
constraint on a TextField,
the implementation must allow only numerals to be entered.
The implementation may provide special formatting for the value entered.
For example, a PHONENUMBER
field may be separated and
punctuated as appropriate for the phone number conventions in use, grouping
the digits into country code, area code, prefix, etc. Any spaces or
punctuation provided are not considered part of the text field's
value. For example, a TextField with the PHONENUMBER constraint might
display as follows:
(408) 555-1212but the value of the field visible to the application would be the string "4085551212". Note that in some networks a '+' prefix is part of the number and is returns as a part of the string.
Field Summary | |
static int |
ANY
The user is allowed to enter any text. |
static int |
CONSTRAINT_MASK
The mask value for determining the constraint mode. |
static int |
EMAILADDR
The user is allowed to enter an e-mail address. |
static int |
NUMERIC
The user is allowed to enter only an integer value. |
static int |
PASSWORD
The text entered must be masked so that the characters typed are not visible. |
static int |
PHONENUMBER
The user is allowed to enter a phone number. |
static int |
URL
The user is allowed to enter a URL. |
Constructor Summary | |
TextField(String label,
String text,
int maxSize,
int constraints)
Creates a new TextField object with the given label, initial contents, maximum size in characters, and constraints. |
Method Summary | |
void |
delete(int offset,
int length)
Deletes characters from the TextField. |
int |
getCaretPosition()
Gets the current input position. |
int |
getChars(char[] data)
Copies the contents of the TextField into a character array starting at index zero. |
int |
getConstraints()
Get the current input constraints of the TextField. |
int |
getMaxSize()
Returns the maximum size (number of characters) that can be stored in this TextField. |
String |
getString()
Gets the contents of the TextField as a string value. |
void |
insert(char[] data,
int offset,
int length,
int position)
Inserts a subrange of an array of characters into the contents of the TextField. |
void |
insert(String src,
int position)
Inserts a string into the contents just prior to the character indicated by the position parameter, where zero specifies the first character of the contents of the TextField. |
void |
setChars(char[] data,
int offset,
int length)
Sets the contents of the TextField from a character array, replacing the previous contents. |
void |
setConstraints(int constraints)
Sets the input constraints of the TextField. |
void |
setMaxSize(int maxSize)
Sets the maximum size (number of characters) that can be contained in this TextField. |
void |
setString(String text)
Sets the contents of the TextField as a string value, replacing the previous contents. |
int |
size()
Gets the number of characters that are currently stored in this TextField. |
Methods inherited from class javax.microedition.lcdui.Item |
getLabel,
setLabel |
Methods inherited from class java.lang.Object |
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
Field Detail |
public static final int ANY
Constant 0 is assigned to ANY.
public static int CONSTRAINT_MASK
getConstraints()
and
CONSTRAINT_MASK in order to retrieve the current constraint mode, in
order to remove any modifier flags such as the PASSWORD flag. Constant 0xFFFF is assigned to CONSTRAINT_MASK.
public static final int EMAILADDR
Constant 1 is assigned to EMAILADDDR.
public static final int NUMERIC
Constant 2 is assigned to NUMERIC.
public static int PASSWORD
The PASSWORD modifier can be combined with any of the input constraints by using the logical OR operator (|).
Constant 0x10000 is assigned to PASSWORD.
public static final int PHONENUMBER
Constant 3 is assigned to PHONENUMBER.
public static final int URL
Constant 4 is assigned to URL.
Constructor Detail |
public TextField(String label, String text, int maxSize, int constraints)
label
- item labeltext
- the initial contents, or null if the TextField is to
be emptymaxSize
- the maximum capacity in charactersconstraints
- see input constraints Method Detail |
public void delete(int offset, int length)
offset
- the beginning of the region to be deletedlength
- the number of characters to be deletedpublic int getCaretPosition()
public int getChars(char[] data)
data
- the character array to receive the value public int getConstraints()
public int getMaxSize()
public String getString()
public void insert(char[] data, int offset, int length, int position)
insert()
.data
- the source of the character dataoffset
- the beginning of the region of characters to copylength
- the number of characters to copyposition
- the position at which insertion is to occur public void insert(String src, int position)
The current size of the contents is increased by the number of inserted characters. The resulting string must fit within the current maximum capacity.
If the application needs to simulate typing of characters it can
determine the location of the current insertion point ("caret") using the
getCaretPosition()
method. For example,
text.insert(s, text.getCaretPosition()) inserts the string
s at the current caret position.
src
- the String to be insertedposition
- the position at which insertion is to occur public void setChars(char[] data, int offset, int length)
data
array starting at array index
offset
and running for length
characters.
If the data array is null, the TextField is set to be empty
and the other parameters are ignored.data
- the source of the character dataoffset
- the beginning of the region of characters to copylength
- the number of characters to copy public void setConstraints(int constraints)
constraints
- see input constraints public void setMaxSize(int maxSize)
maxSize
- the new maximum size public void setString(String text)
text
- the new value of the TextFieldpublic int size()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |