+ All Categories
Home > Business > 12 High Level UI Event Handling

12 High Level UI Event Handling

Date post: 21-Jun-2015
Category:
Upload: corneliuskoo
View: 1,476 times
Download: 3 times
Share this document with a friend
Popular Tags:
27
High Level UI Components Event Handling Cornelius Koo - 2005
Transcript
Page 1: 12 High Level UI Event Handling

High Level UI Components

Event Handling

Cornelius Koo - 2005

Page 2: 12 High Level UI Event Handling

What is Event Handling

• Process of recognizing when an event

occurs and taking an action based on that

event.

Page 3: 12 High Level UI Event Handling

3 Steps in Event Management

1.The hardware must recognize that something

has occured : button pressed, mouse clicked,

mouse hover, an adapter plugged in etc.

2.The software on the device needs to be notified

of the event.

3. A message from the application manager will be

sent to the MIdlet. The message would contain

information about the event, so that we can

process it.

Page 4: 12 High Level UI Event Handling

Scenario

Page 5: 12 High Level UI Event Handling

Listener

• Before MIDlet can accept and process an

event, it must implements Listener

interfaces.

• There are 2 Listeners in MIDP :

1. CommandListener

2. ItemStateListener

Page 6: 12 High Level UI Event Handling

public class TestCommandListener

extends MIDlet implements

CommandListener {

...

public void commandAction(Command c,

Displayable s) {…}

}

Page 7: 12 High Level UI Event Handling

public class TestItemStateListener

extends MIDlet implements

ItemStateListener {

...

public void itemStateChanged(Item

item) {}

}

Page 8: 12 High Level UI Event Handling

Command Object

• Command object is an object that holds

information about an event.

Page 9: 12 High Level UI Event Handling

Processing Events

• Processing events steps :

1. Create a Command object to hold

information about an event.

2. Add the Command to a Form, Textbox,

List or Canvas.

3. Add a "listener" to the above Form,

Textbox, etc.

Page 10: 12 High Level UI Event Handling

private Display display;

private Command cmExit;

private Form fmMain;

public TestDisplayable() {

super();

display = Display.getDisplay(this);

fmMain = new Form("Displayable Form");

cmExit = new Command("Exit", Command.EXIT, 1);

fmMain.addCommand(cmExit);

fmMain.setCommandListener(this);

}

Page 11: 12 High Level UI Event Handling

Item Object

• Any components that can be added to a Form.

• ChoiceGroup, DateField, Gauge and

TextField are all subclasses of Item and

each can process events.

Page 12: 12 High Level UI Event Handling

StringItem & ImageItem

• StringItem and ImageItem are also

subclasses of Item however once

allocated, these objects are static and thus

do not receive/acknowledge events.

Page 13: 12 High Level UI Event Handling

Command

1. Label

2. Type

3. Priority

Page 14: 12 High Level UI Event Handling

label

• Specifies the text you would associate with

the text.

Page 15: 12 High Level UI Event Handling

type

• Specify the type of specific soft button.

Page 16: 12 High Level UI Event Handling

priority

• Used by application manager when

arranging items that appear in a menu or

for ordering soft buttons on the display.

Page 17: 12 High Level UI Event Handling

Command Types

Page 18: 12 High Level UI Event Handling

Command & CommandListener API

Page 20: 12 High Level UI Event Handling

ItemListener

• When an item’s value changed, it will

generate an item event and sent it to

ItemListener. (Except for StringItem and

ImageItem)

Page 21: 12 High Level UI Event Handling

When it is called ?

• If an Item has changed, itemStateChanged() must be called for the changed Item before it will acknowledge changes in a subsequent Item.

• If a MIDlet makes a change to an Item (not a user interaction), itemStateChanged() will not be called.

• If the device running the MIDlet can recognize when a user has moved from one Item to another, itemStateChanged() must be called when leaving one Item and before getting to the next.

Page 22: 12 High Level UI Event Handling

Item & ItemListener API

Item

ItemListener

Page 23: 12 High Level UI Event Handling

List Select Command

• We can change the select command for

List and set it to our own command.

Page 24: 12 High Level UI Event Handling

private List lsHero;

private Command cmOpen = new

Command(“Open",Command.ITEM,1);

private String[] sound = {

"Info",

"Confirmation",

"Warning",

"Alarm",

"Error“

};

Page 25: 12 High Level UI Event Handling

...

lsHero = new List("Message Type",

List.IMPLICIT, sound, null);

lsHero.setSelectCommand(cmOpen);

lsHero.setCommandListener(this);

...

Page 26: 12 High Level UI Event Handling

public void commandAction(Command arg0,

Displayable arg1) {

if(arg0 == cmOpen){

System.out.println(“Open selected");

System.out.println(

((List)arg1)

.getString(((List)arg1)

.getSelectedIndex())

);

}

}

Page 27: 12 High Level UI Event Handling

Reference

• Core J2ME Technology and MIDP. John

W. Muchow. Prentice Hall PTR, 2002.

• Enterprise J2ME: Developing Mobile

Java Applications. Michael Juntao Yuan.

Prentice Hall PTR, 2003.

• J2ME in A Nutshell. Kim Topley. Oreilly,

2002.


Recommended