Our midlet start showing a form in which to insert the name of a friend of ours and his three phone numbers. The class that we use to start with, is the class Form : the use of other objects that derive from Screen is similar to what we shall see below. Form is an object that contains a set of components, which are derived from Item , which may be added and then displayed and used in accordance with the features provided by the user. To enter the name and three phone numbers of our friend, use TextField , a component that allows you to enter data into a text field.
Code:
//...
private Display display;
private Form form;
private TextField name;
private TextField PHONE1;
private TextField Phone2;
private TextField phone3;
public HighUI ()
{
function ();
display = Display.getDisplay (this);
form = new Form ("Contact");
name = new TextField ("Name", null, 30, TextField.ANY);
PHONE1 = new TextField ("Tel1", null, 15, TextField.PHONENUMBER);
Phone2 = new TextField ("Tel2", null, 15, TextField.PHONENUMBER);
phone3 = new TextField ("Tel3", null, 15, TextField.PHONENUMBER);
form.append (name);
form.append (PHONE1);
form.append (Phone2);
form.append (phone3);
.....
}
protected void startApp () throws MIDletStateChangeException
{
display.setCurrent (form);
}
// ...
We create the object Form specifying the title and subsequent TextField :
Code:
PHONE1 = new TextField ("Tel1", null, 12, TextField.PHONENUMBER);
The previous construct specifies:
- the label text field ( eg Tel1: );
- the initial contents of the field (eg, null indicates that it must be empty);
- the maximum allowable size (eg 12);
- any input constraints (eg TextField.PHONENUMBER to force the inclusion of a telephone number; TextField.ANY do not set constraints).
Bookmarks