+ All Categories
Home > Documents > J2ME Screen Hierarchy

J2ME Screen Hierarchy

Date post: 07-Feb-2016
Category:
Upload: lucius
View: 42 times
Download: 0 times
Share this document with a friend
Description:
J2ME Screen Hierarchy. Displayable. Screen. Canvas. Form. Alert. List. Textbox. Form. A screen that contains arbitrary items Selected methods: int append(Image img) int append(Item item) int append(String str) void insert(int itemNum, Item item) void delete(int itemNum) - PowerPoint PPT Presentation
19
J2ME Screen Hierarchy Displayable Screen Canvas Form Alert List Textbox
Transcript
Page 1: J2ME Screen Hierarchy

J2ME Screen Hierarchy

Displayable

Screen Canvas

Form Alert List Textbox

Page 2: J2ME Screen Hierarchy

Form A screen that contains arbitrary items Selected methods:

int append(Image img)int append(Item item)int append(String str)void insert(int itemNum, Item item)

void delete(int itemNum)void deleteAll()

Item get(int itemNum)void set(int itemNum, Item item)void setItemStateListener(ItemStateListener iListener)

int size()

Page 3: J2ME Screen Hierarchy

List

A screen that represents selection of choices Types of List

List.MULTIPLE – selection of multiple options (checkboxes)

List.EXCLUSIVE – single-option selection only (radiobuttons)

– selection is triggered via a command

List.IMPLICIT – single-option selection only

– selection is triggered implicitly (List.SELECT_COMMAND)

Page 4: J2ME Screen Hierarchy

IMPLICIT EXCLUSIVE MULTIPLE

(SUN WTK Emulator)

Page 5: J2ME Screen Hierarchy

IMPLICIT EXCLUSIVE MULTIPLE

(Nokia S60 Emulator)

Page 6: J2ME Screen Hierarchy

List

Creating Lists (List API)

List(String title, int listType) creates new, empty List, specifying its title and the type of the list

List(String title, int listType, String[] stringElements, Image[] imageElements) creates new List, specifying its title, the type of the List, and an

array of Strings and Images to be used as its initial contents

best image width/height for List element Image Icon: 16x16 (WTK emulator) 57x41 (Nokia S60 3rd Ed FP 2 Emulator) …

– your phone? Display d = Display.getDisplay(this);

int biw = d.getBestImageWidth(Display.LIST_ELEMENT);

int bih = d.getBestImageHeight(Display.LIST_ELEMENT);

Page 7: J2ME Screen Hierarchy

List

Selected methods

int append(String stringPart, Image imagePart) -- append an element to the List

void delete(int index) -- delete the element at the given index

Image getImage(int index) -- gets the Image part of the given element

String getString(int index) -- gets the String part of the given element

int getSelectedFlags(boolean[] choices) -- returns the state of all elements

(use with List.MULTIPLE)

int getSelectedIndex() -- returns the index of an element in the List that is selected

(use with List.IMPLICIT, List.EXCLUSIVE)

Page 8: J2ME Screen Hierarchy

List Example Creating List

List payMethod = new List(“Payment method”, List.EXCLUSIVE);payMethod.append(“Credit Card”, null);payMethod.append(“PayPal”, null);payMethod.append(“Bank Acct”, null);

okCmnd = new Command(“OK”, Command.OK, 1);payMethod.addCommand(okCmnd);

payMethod.setCommandListener(...);

Processing Selection (in CommandListener)

void commandAction(Command c, Displayable d){

if (c == okCmnd && d == payMethod) {int index = payMethod.getSelectedIndex();if (index == CCARD) { }

}}

Page 9: J2ME Screen Hierarchy

List Appearance

Control with void setFitPolicy(int policy)

Choice.TEXT_WRAP_ON – long list items shown on multiple lines

Choice.TEXT_WRAP_OFF – truncate long list items to fit on one line

Choice.TEXT_WRAP_DEFAULT – use default policy (e.g. truncate with …)

Page 10: J2ME Screen Hierarchy

Lab Exercise Create an application that demonstrates the three types of List screen

Page 11: J2ME Screen Hierarchy

Images

MIDP implementations required to support PNG format

Place image files in project resource folder – res/

Loading images

Image logo = null;try {

logo = Image.createImage(“/gburg.png”);} catch (IOException e) {

... handle exception ...}

Page 12: J2ME Screen Hierarchy

Alert Screen

Intended for showing notification messages

Creating Alerts

Alert(String title, String alertText, Image alertImage, AlertType alertType) constructs a new Alert object with the given title, content, image, and type.

Alert types – WARNING, ERROR, INFO, CONFIRMATION

Screen sequencing and alerts

Form receipt = new Form(“Receipt Details”);

Alert confirm = new Alert(“Finished”, “The order is submitted!”, null, CONFIRMATION);

Display.setCurrent(confirm, receipt);

Page 13: J2ME Screen Hierarchy

Alert("ERROR Type", "Error condition notification!", null, AlertType.ERROR)

Page 14: J2ME Screen Hierarchy

Alert("WARNING Type", "Warning condition notification!", null, AlertType.WARNING)

Page 15: J2ME Screen Hierarchy

Alert("INFO Type", "Information message!", null, AlertType.INFO)

Page 16: J2ME Screen Hierarchy

Alert("CONFIRMATION Type", "Confirm to proceed!", null, AlertType.CONFIRMATION)

Page 17: J2ME Screen Hierarchy

Alert Screen

Selected methods

Image getImage() -- gets the Image used in the Alert

Gauge getIndicator() -- gets the activity indicator for this Alert

String getString() -- gets the text string used in the Alert

AlertType getType() – gets the type of the Alert

int getTimeout() -- gets the time this Alert will be shown

void setTimeout(int t) -- sets the time this Alert will be shown

Page 18: J2ME Screen Hierarchy

Gauges

Used to show progress or get user input

Types of gauges interactive – get user input (e.g. sliders) non-interactive, continuous – show operation is executing non-interactive, incremental – show progress (app should increment)

Page 19: J2ME Screen Hierarchy

Gauges

Used to show progress or get user input

Types of gauges interactive – get user input (e.g. sliders) non-interactive, continuous – show operation is executing non-interactive, incremental – show progress (app should increment)

Gauge g1 = new Gauge("Interactive", true, 10, 5);

Gauge g2 = new Gauge("Non-Interactive, Continuous", false,

Gauge.INDEFINITE, Gauge.CONTINUOUS_RUNNING);

Gauge g3 = new Gauge("Non-Interactive, Incremental", false,

Gauge.INDEFINITE, Gauge.INCREMENTAL_UPDATING);


Recommended