Beruflich Dokumente
Kultur Dokumente
Contents
Commands on items
Abstraction
Discovery
MIDP - UI APIS
High-level API
Low-level API
Examples:
draw
in a canvas: paint(Graphics g)
call
Displayable structure
javax.microedition.lcdui
Displayable
javax.microedition.lcdui.game
Canvas
GameCanvas
Screen
Screen Abstraction
Alert
List
Form
TextBox
Canvas Discover
Using Display
Command Types
OK
CANCEL
BACK
STOP
HELP
SCREEN
EXIT
ITEM
Confirm a selection
Cancel pending changes
Moves the user back to a previous screen
Stops a running operation
Show application instructions
Generic type for specific application commands
A command used for exiting from the application
Command used for items (focused item or element)
10
Creating Commands
A standard OK command
Command c = new Command (OK, Command.OK, 0);
Responding to commands
Command example
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
code
Command example - II
If you continue adding commands, the ones that dont fit on the
screen will be put into an off-screen menu
If you press the soft button for Menu youll see the remainder of
the commands
15
Screens
Alert
List
Form
16
17
Textbox
Textbox II
Using Alerts
20
Alerts
Alerts
22
Alerts Example
23
code
24
25
Using List
27
Creating List
List constructors:
Public List(String title, int type)
Public List(String title, int type,
String[] stringElements, image[] imageElements)
Editing a List
Insert at index
Set at index
Remove an Element
Number of Elements
29
31
32
code
34
35
About Images
createImage(String name)
createImage(byte[] imagedata,
int imageoffset, int imagelength)
From a buffer
createImage(InputStream stream)
From a stream
36
You could ask the Display what is the best image size for a
particular usage (LIST_ELEMENT, ALERT, or
CHOICE_GROUP_ELEMENT):
37
Managing Items
Items - StringItem
Items - StringItem
41
Item Commands
public class MyHello extends MIDlet {
private Form mform;
private StringItem mItem;
code
public MyHello () {
mform = new Form("Hello Form");
mItem = new StringItem("hello: \n", "Hello my students!");
mform.append(mItem);
mItem.addCommand(new Command("Exit from Item", Command.ITEM, 0));
mItem.setItemCommandListener(new ItemCommandListener() {
public void commandAction(Command command, Item item) {
notifyDestroyed();
}
});
}
public void startApp() {
Display.getDisplay(this).setCurrent(mform);
}
43
Item size
44
Item Layout
Item has methods - getLayout() and setLayout() related to layout control - There is no Form layout
Form attempts to lay out items left-to-right in rows,
stacking rows top-to-bottom
Usually the layout value is a combination of LAYOUT_2
(MIDP 2.0 rules) with a horizontal value and vertical value
Horizontal Values: LAYOUT_LEFT,LAYOUT_RIGHT,
LAYOUT_CENTER
Vertical Values: LAYOUT_TOP, LAYOUT_BOTTOM,
LAYOUT_VCENTER
Request a new-line after/before the item:
LAYOUT_NEWLINE_AFTER, LAYOUT_NEWLINE_BEFORE
Example
int prefLayout = Item.LAYOUT_2 | Item.LAYOUT_LEFT
| Item.LAYOUT_NEWLINE_AFTER;
mVideoItem.setLayout(prefLayout);
45
Items TextField
Items - ImageItem
Example:
waitImage = Image.createImage("/wait.png");
mColorSquare = new ImageItem(label, waitImage,
ImageItem.LAYOUT_DEFAULT, alt text");
LAYOUT_NEWLINE_BEFORE, LAYOUT_NEWLINE_AFTER
Items - DateField
Items - Gauge
code
52
Items - ChoiceGroup
54
code
56
ItemStateChanged
PLAIN, HYPERLINK,BUTTON
Summary on Commands
d.addCommand(c);
d.setCommandListener(cl);
commandAction(Command c, Displayable s)
i.setItemCommandListener(icl);
61