High Level User Interface: 3.1 Objectives
High Level User Interface: 3.1 Objectives
Chapter 3
High Level User Interface
3.1 Objectives
At the end of the lesson, the student should be able to:
Know the advantages and disadvantages of using high-level and low-level UI classes
Form object
High Level UI
Low-Level UI
may be device-specific
J.E.N.I.
High Level UI
no access to device specific features
Low-Level UI
access to low-level
input like key presses
When you want your application to be easily interchanged with different kinds of
equipment (Portability)
When you want your application to have the same look as other UI components of
various equipment.
When you want your code to be as little as possible, when an interaction is handled by
API
When your application requires the exact spot of the elements that exists on screen
When creating a graphical game; although you can still use high-level UI in the game
menu, it is more advisable to make UI menu on your own to avoid seamless
atmosphere for the user
When an application requires access to low-level input that has such key presses
3.2.1
Display
The core of the MIDP user interface is the display. There is only one and only one instance
of Display is per MIDlet. The MIDlet can get a reference to the Display object by using the
static Display.getDisplay()method, passing a reference to the MIDlet instance.
The MIDlet is guaranteed that the Display object will not change within the MIDlets
instances existence. This means that the variable returns (returned) when you call
getDisplay() and it will not matter if you call with startApp() or destroyApp() (Look at the
Midlet Life Cycle images).
J.E.N.I.
3.2.2
Displayable
Only one Displayable is displayed at a time. By default, a Displayable is not visible on the
Display. A Displayable can be displayed by calling the setCurrent() method of the Display
instance. The setCurrent() method should be called at the start of the application,
otherwise, a blank screen will be displayed or the application will not start.
startApp method of MIDlet is a place where you can put setCurrent caller method (). But
you have to consider that MIDlet startApp() can be called more than once. To dismiss close
MIDlet temporarily pause by calling the pauseApp() function on incoming call, startApp() is
called again (after an incoming call) to enable. Thus, by calling the method setCurrent() on
startApp(), the possibility of the display will be dark (blank) on a screen displayed
previously, until the cessation (pause by the phone call)
A displayable could have name, some (command), CommandListener and Ticker.
J.E.N.I.
3.2.3
Title
A Displayable has a title associated with itself. The position and appearance of the title is
device specific and can only be determined by device. A title is attached to a Displayable
by calling setTitle(). Calling this method will immediately update the title of the Displayable.
If the Displayable is currently displayed on the screen, the MIDP specification states that
the title should be changed by the implementation "as soon as it is feasible to do so".
Null parameter gives setTitle() to erase the Displayable title. Changing or deleting a title
can affect the size of Displayable area for the contents of the Displayable referred to. If the
size of the area changes, MIDlet will be notified with a call back method sizeChanged().
3.2.4
Command
With the shortage of size on the screen, MIDP does not describe a menu bar. In place of
the menu bar, MIDlet have Commands. A Command is usually implemented by the MIDP
implementation as a soft key or an item in a menu. A Command Object only contains
information about the action to be taken when it is activated. It does not contain code that
would be executed when it is selected.
The CommandListener property of a Displayable contains actions that are to be executed
upon the Commands activation. CommandListener is a specific interface on a single
method:
Pengembangan Perangkat Mobile
J.E.N.I.
J.E.N.I.
Command.OK, Command.BACK,
Command.CANCEL, Command.EXIT,
Command.HELP, Command.ITEM,
Command.SCREEN, Command.STOP
J.E.N.I.
3.2.5
CommandListener
J.E.N.I.
3.2.6
Ticker
Ticker is a line of text that can be scrolling continuously on display. Constructor method of
ticker receives text string for display. The only two other case methods, i.e. getters and
setters for this text: String GetString() and void setString(String text). There is no other
way in an application to control the speed and direction of scrolling text. Scrolling cannot
be paused or stopped.
If space is placed in the text, it will not be displayed on the screen. All lines of text will be
displayed as a single line of scrolling text.
A ticker can be mounted on a Displayable by calling setTicker(). If Displayable ticker has
been there on, it will be replaced by a new ticker contained in the parameter.
Null parameter gives the ticker setTicker to replace all that has been put on Displayable.
Removing ticker of Displayable can cause changes in the size of the area of the Displayable
contents. If the area size changes occur, then MIDlet will call a method size with
sizeChanged()
Displayable object ticker may not share an event (action).
3.2.7
Screen
Screen is the essence of abstract class that is used for high-level UI while the Displayable
canvas abstract class is for low-level UI.
Here are four subclasses of the abstract class screen: Form, TextBox, List and Alert.
J.E.N.I.
3.2.8
Item
Items is a component that can be put into a container, such as Form or Alert. An item can
have the following properties:
Property
Default Value
Label
Commands
defaultCommand
Null
ItemCommandListener
Null
Layout directive
LAYOUT_DEFAULT
-1 (unlocked)
J.E.N.I.
Here are the vertical alignment directive which are also mutually exclusive:
LAYOUT_TOP
LAYOUT_BOTTOM
LAYOUT_VCENTER
3.3 Alert
An alert is a screen that can display a text and an image. An alert is a component for
displaying error, a warning, display text and image information, or to get confirmation from
the user.
The Alert is displayed for a specific period of time. This time is set using the setTimeout()
method and is specified in milliseconds unit. It can be made to be displayed until the user
activates the command ("Done") by specifying a special timeout of Alert.FOREVER.
10
J.E.N.I.
Alert can also display components Gauge (See the item Gauge) as indicator.
When the alert contains text that does not comply with the screen and should scroll, then
automatically sets the alert to capital (timeout is set to Alert.FOREVER).
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
Alert[] alerts = {
new Alert("Alarm Alert",
"Example of an Alarm type of Alert",
null, AlertType.ALARM),
new Alert("Confirmation Alert",
"Example of an CONFIRMATION type of Alert",
null, AlertType.CONFIRMATION),
new Alert("Info Alert",
"Example of an INFO type of Alert",
null, AlertType.INFO),
new Alert("Warning Alert",
"Example of an WARNING type of Alert, w/ gauge indicator",
null, AlertType.WARNING),
11
J.E.N.I.
public AlertExample(){
mainForm = new Form("JEDI: Alert Example");
mainForm.addCommand(exitCommand);
for (int i=0; i< commands.length; i++){
mainForm.addCommand(commands[i]);
}
mainForm.setCommandListener(this);
// Set alert
alerts[5].setTimeout(Alert.FOREVER);
}
12
J.E.N.I.
INFO Alert
Modal Alert
3.4 List
The Lists are a subclass of the Screen containing a list of a choice. A List can be of three
types: IMPLICIT, EXCLUSIVE or MULTIPLE.
13
J.E.N.I.
If the List is IMPLICIT and the user executes the "select" button, commandAction() of the
Lists commandListener will be called. The default command is List.SELECT_COMMAND.
For the type of IMPLICIT and EXCLUSIVE, GetSelectedIndex() returns the index of the
selected element. For type MULTIPLE, getSelectedFlags() returns a boolean that contains
an array of state of the elements. IsSelected (int index) restore the state of the elements
in the provision of index positions.
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public ListExample(){
list = new List("JEDI: List Example", List.IMPLICIT);
list.append("List Item #1", null);
list.append("List Item #2", null);
list.append("List Item #3", null);
list.setTicker(ticker);
list.addCommand(exitCommand);
list.addCommand(newCommand);
list.addCommand(renameCommand);
list.addCommand(deleteCommand);
list.setCommandListener(this);
14
J.E.N.I.
15
J.E.N.I.
List.IMPLICIT
List.EXCLUSIVE
List.MULTIPLE
16
J.E.N.I.
3.6 Form
The Form is a subclass of Screen. It is a container for subclass items, such as TextField,
StringItem, ImageItem, DateField and ChoiceGroup. It handles the layout of these
components. It also handles traversal among the components and scrolling of the screen.
Item added and put into a form using the method append() and insert(), respectively.
Item referenced using a zero-based index.
3.7 ChoiceGroup
The ChoiceGroup item is a group of selectable choice. The choice may contain a text, an
image or both.
The choices may be EXCLUSIVE (only one choice can be selected) or MULTIPLE (multiple
choices can be selected at a time). If a ChoiceGroup is of type POPUP, only one choice is
displayed. A popup selection will be displayed when this item is selected. From this popup
selection, the user may select his choice. The choice displayed is always the selected choice.
17
J.E.N.I.
18
J.E.N.I.
DateField dateonly =
new DateField("Birthday (DATE)", DateField.DATE);
DateField timeonly =
new DateField("Set Alarm (TIME)", DateField.TIME);
19
J.E.N.I.
DateField datetime =
new DateField("Departure (DATE_TIME)", DateField.DATE_TIME);
dateForm.append(dateonly);
dateForm.append(timeonly);
dateForm.append(datetime);
Selecting a date
Time input
20
J.E.N.I.
stringForm.append(plain);
stringForm.append(hyperlink);
stringForm.append(button);
Figure: StringItem
21
J.E.N.I.
try {
Image img = Image.createImage("/jeni.png");
ImageItem image =
new ImageItem("JENI", img, Item.LAYOUT_CENTER, "jeni logo");
imageForm.append(image);
} catch (Exception e){e.printStackTrace();}
jeni.png fil e i s very important for input into the project by using operating system's
manager and put the image into the project directory under the subdirectory "src". Then
the project is reloaded by right-clicking the name project and select "Refresh Folders".
22
J.E.N.I.
Figure: ImageItem
23
J.E.N.I.
TextField.ANY
TextField.EMAILADDR
TextField.NUMERIC
TextField.PHONENUMBER
TextField.URL
TextField.DECIMAL
TextField.ANY);
TextField EMAILADDR =
new TextField("EMAILADDR", "", 64,
TextField.EMAILADDR);
TextField NUMERIC =
new TextField("NUMERIC", "", 64,
TextField.NUMERIC);
TextField PHONENUMBER =
24
J.E.N.I.
TextField.PHONENUMBER);
TextField URL =
new TextField("URL", "", 64,
TextField.URL);
TextField DECIMAL =
new TextField("DECIMAL", "", 64,
TextField.DECIMAL);
textForm.append(ANY);
textForm.append(EMAILADDR);
textForm.append(NUMERIC);
textForm.append(PHONENUMBER);
textForm.append(URL);
textForm.append(DECIMAL);
25
J.E.N.I.
3.12 Exercise
3.12.1 D y n a m i c List
Create a MIDlet that has implicitly as List Screen play. Put three Command added to this
List - "Add Item", "Remove Item" and "Exit". Command "Add Item" will provide services to
the user to enter the list using TextBox, then insert the item before current selected item
from the list. "Remove Item" will remove the currently selected list item
(getSelectedIndex). Command "Exit" will out of the program.
26