High Level UI
High Level UI
We will go through the high level API briefly. Remember, it is not comprehensive. You need to follow the API documentation to know about all the features. That is easy once you have got a taste of it.
Check the program AlertDemo.java
- They are used to convey a short message to the user.
- Alerts can be of five types INFO, WARNING, ERROR, ALARM, and CONFIRMATION corresponding to its purpose. A sound can be played according to the type of alert, the sound dependent on the device.
- A title must be passed to the Alert constructor e.g. Alert("Title"), which can't be changed subsequently. Another constructor is also there which takes more arguments in addition to the title.
- The message is set as setString("Message to display").
- The time for which an alert is shown is determined by setTimeout(int time) where 'time' is in milliseconds. It can be set as Alert.FOREVER to keep it displayed till the user dismisses it. I suggest that you set it to FOREVER or a high value during development so that you don't miss it, during actual deployment the time out might be set less.
- An image may be attached to the alert using setImage(Image image).
Check the program ListDemo.java
- It is used when a user need to select one or multiple elements from an available set of options
- It can be of three types Choice.EXCLUSIVE (only one element can be selected) Choice.MULTIPLE (multiple elements can be selected), or Choice.IMPLICIT (the currently highlighted element is selected). Change the list type in the given example and see how the look and functioning alter.
- Each option (basically a String) in a List can have an image associated with it.
- A list can either be created blank and choices can be appended to it or a set of choices can be constructed first and a List can be created with that set.
List (String title, int listType)
List (String title, int listType, String  stringElements, Image  imageElements)
- A textbox lets a user input text.
- It has six constraint settings for restricting content: ANY, EMAILADDR, NUMERIC, PHONENUMBER, URL, and DECIMAL. ANY allows all kinds of text to be entered, while the rest constrain according to their names.
- Similarly, there are six constraint settings that affect the display. These are: PASSWORD, UNEDITABLE, SENSITIVE, NON_PREDICTIVE, INITIAL_CAPS_WORD, and INITIAL_CAPS_SENTENCE.
- Not all of these settings may be functional in all devices.
- If you want a combination just do OR operation on the two Constraints.
- If you want a user to input a 4-digit PIN number, construct the text box as
pinInput = new TextBox("Input PIN", "", 4, TextField.NUMERIC | TextField.PASSWORD);
Check the program FormDemo.java
- It contains a collection of items. You can set and place the times according to your need inside a form.
- StringItem - Used to place a String not modifiable by the user. Form also provides a shortcut append(String stringItem) to append strings.
- DateField - Used to add date and time info.
- TextField - similar to TextBox.
- ChoiceGroup - similar to List.
- Spacer - Empty element to provide space between other elements, used to control placement of elements in UI design.
- Gauge - It can either be used to denote progress in a process e.g. downloading a file or it can be an interactive element e.g. a volume control.
- ImageItem - Used to display image. A shortcut to add image to Form is append(Image imageItem).
- CustomItem - It is an abstract class, which you can extend to design your own element with its own look, interactivity etc.
Before we move on, few points to note -
- Dismissing an Alert automatically brings back previous screen. When an alert disappears (either expiring the timeout limit or manually by the user), the previous displayed object is automatically set visible.
- A change in a displayable unit is displayed instantaneously if it's visible. Say a list was being displayed with 3 options and the program adds a fourth option, it is made visible to the user immediately, no need to 'refresh' manually.