J2ME Screen Hierarchy

Post on 07-Feb-2016

42 views 0 download

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

transcript

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)void deleteAll()

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

int size()

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)

IMPLICIT EXCLUSIVE MULTIPLE

(SUN WTK Emulator)

IMPLICIT EXCLUSIVE MULTIPLE

(Nokia S60 Emulator)

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);

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)

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) { }

}}

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 …)

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

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 ...}

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);

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

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

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

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

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

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)

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);