J2ME UI Architecture
J2ME UI Architecture
J2ME applications use the javax.microedition.lcdui package to implement the user interface on the LCD screens of mobile devices. Here we will go through the basic structure of the LCD UI implementation followed by a little detail about how to use the high and low level elements and handling commands. This wonâ€™t be a very detailed study. After this brief knowledge, you can always look at the API documentation and learn about the specific features of each element.
How do they appear? Display & Displayable
Before we start looking into the specific elements, letâ€™s first know how the display functions in java lcdui.
- Only a displayable object i.e. one that extends the Displayable class can be displayed.
- Only one object can be displayed at a time. You can construct and design as many displayable objects you like but one and only one can be displayed at a time.
- Display class represents the display manager. It has a static getDisplay(MIDlet m) function which returns the display object unique to the MIDlet.
- A MIDlet has only one unique instance of display.
- The function setCurrent (Displayable newDisplayElement) is called on the display instance to display newDisplayElement on the screen. Remember, as soon as this is displayed, the older element that was being displayed previously is removed from display. However the object is not destroyed. You can re-display it calling the setCurrent() again.
- The getCurrent() function returns the currently displaying element.
User Interface Architecture
As you might already have guessed, the grandfather of all display elements is the Displayable class. It has too children â€“
- Screen â€“ It is the father of all high-level display elements. High-level means that the elements have a structure set already, you just need to customize them according to your need. These are easy to use for specific type of displays but you canâ€™t to manipulation at a lower level.
- Canvas â€“ It allows you to do the low level graphics e.g. drawing shapes, manipulating images etc. It uses a Graphics object for this purpose. It has no children.
Screen is extended by a number of children â€“
- Alert â€“ To show short texts regarding information, warning, error etc.
- List â€“ To show a list of options from which one or a combination of options might be selected
- Textbox â€“ To get text inputs from users
- Form â€“ Form is a placeholder in which a combination of Items can be placed. There are eight types of Items (classes that implements the Item interface) namely StringItem, DateField, TextField, ChoiceGroup, Spacer, Gauge, ImageItem, CustomItem.
In the next section we will learn how to work with the high-level display elements i.e. the children of Screen.