MAD Lecture 3 - MIDP GUI Programming Handouts
MAD Lecture 3 - MIDP GUI Programming Handouts
The MIDP user interface API is divided into a high- and Low level API
low-level API. Low-level API provides little abstraction.
High Level API It is designed for applications that need precise
High level API Is designed for applications where portability placement and control of graphic elements, as well as
between mobile information devices is important.
access to low-level input events
To achieve portability, the API employs a high level abstraction
and gives you little control over its look and feel. This API gives the application full control over what is
The high-level API provides input elements such as text fields, being drawn on the display
choices, and gauges. There are only two fixed levels: Screens and E.g javax.microedition.lcdui.Canvas, javax.microedition.lcdui.Graphics
Items. The Items can be placed in a Form, which is a specialized
Screen.
1
MIDP GUI Model MIDP GUI Model
MIDlet
The high-level Screens and the low-level class Canvas
have the common base class Displayable. Display
All subclasses of Displayable fill the whole screen of the
device. Displayable Command
Display
To show something on a MIDP device, you’ll need to obtain the
device’s display – javax.microedition.lcdui.Display class
Provides methods to retrieve information about the device’s
display capabilities
Screen
Encapsulates and organises graphics objects and coordinates
user input through the device. – javax.microedition.lcdui.Screen
and are shown by the Display object by calling its setCurrent()
method.
There can be several screens in an application, but only one
screen at a time can be visible in a display, and the user can only
traverse only through the items on that screen
2
MIDP GUI ( Contd) MIDP GUI ( Contd)
Alert List
An alert is an ordinary screen that can contain text and image A list is a screen containing selectable choices
It informs the user about errors and other exceptional conditions
Both List and ChoiceGroup have common behaviour
An alert can either be modal or timed
Modal
defined by choice interface
The alert remains on the screen until the user dismisses it
Class List
Timed Alert
It is displayed for a certain amount of time
Public List( String Title, int listType);
Alert Class Public List(String title, int listType, String[] stringElements,
Public Alert(String title) image[] imageElements);
Public Alert(String Title, String alertText, Image alertImage. AlertType alertType)
3
MIDP GUI ( Contd) MIDP GUI ( Contd)
DateField Gauge
A DateField object is an editable component for representing A gauge is used to represent the progress of certain tasks
calendar date and time information that can be placed on a Form
object. A Gauge can be
Can be configured to accept date or time information, or both. Interactive
A gauge object represents a bar graph that can be used within a form
Datefield Class or Non-interactive
Public DateField( String label, int mode) A non-interactive gauge can be used to represent the progress of a certain task .
Public DateField( String label, int mode, TimeZone timezone) It is used when you don’t know how long a particular activity will take
A non-interactive gauge that has an INDEFINITE maximum
Public Date getDate() This type of gauge can be in one of four states, and this is reflected by the initial
Public int getInputMode() value
CONTINUOUS_IDLE, INCREMENTAL_IDLE, CONTINUOUS_RUNNING, and
Public void setDate( Date date)
INCREMENTAL_UPDATING
Public void setInputMode( int mode); Each state represents the best effort of the device to let the user know the current
activity of the MIDlet, and you can use them to represent these states yourself
Note: mode can be DateField.DATE,TIME,DATE_TIME
4
MIDP GUI ( Contd) MIDP GUI ( Contd)
Images can either be Class imageItem
Immutable or Public imageItem( String label, image img, int layout, String
Created by loading image data from resource bundles, files etc. altText)
Once created they cannot be modified Layout can be the followings
Public static Image createImage( Image image) ImageItem – LAYOUT_CENTER, LAYOUT_DEFAULT, LAYOUT_LEFT,
Public static Image createImage( String name) LAYOUT_NEWLINE_AFTER, LAYOUT_NEWLINE_BEFORE,
LAYOUT_RIGHT,
Public String getAltText()
Mutable
Public image getImage()
It is created in off-screen memory and can be modified/ edited
An image created this way initially has all of its pixels set to white, and
Public int getLayout()
you can acquire a graphics object on this image by using the method Public void setAltText( string altText)
getGraphics() to modify the way it is rendered on screen Public void setImage(Image img)
Public static Image createImage( int width, int height) Public void setLayout( int layout)