13 Low Level UI Event Handling

14
Low Level UI Components Event Handling Cornelius Koo - 2005

description

 

Transcript of 13 Low Level UI Event Handling

Page 1: 13 Low Level UI Event Handling

Low Level UI Components

Event Handling

Cornelius Koo - 2005

Page 2: 13 Low Level UI Event Handling

Low Level

• 2 Kind of interaction between User and

Canvas :

1. Commands

2. Low Level Events

Page 3: 13 Low Level UI Event Handling

Commands Canvas

• Canvas is a Displayable object.

• It can accept Commands.

• It can interact with CommandListener.

Example MIDlet : TestCommandCanvas.java

Page 4: 13 Low Level UI Event Handling

Key Codes

Page 5: 13 Low Level UI Event Handling

Key Code Methods

javax.microedition.lcdui.Canvas

Page 6: 13 Low Level UI Event Handling

Key Detection

• To do a low level event handling, we must

detect keys and pointers.

• This Detection process is implemented

through key code methods overriding.

Page 7: 13 Low Level UI Event Handling

protected void keyPressed(int

keyCode) {

if (keyCode == KEY_NUM1)

...

else if (keyCode == KEY_NUM2)

...

}

Page 8: 13 Low Level UI Event Handling

Game Action

• A set of constant to facilitate event

handling for game appication.

Page 9: 13 Low Level UI Event Handling
Page 10: 13 Low Level UI Event Handling

Game Action Constants

Page 11: 13 Low Level UI Event Handling
Page 12: 13 Low Level UI Event Handling

Example MIDlet : TestGameAction.java

Page 13: 13 Low Level UI Event Handling

Converter Methods

• public int getGameAction(int

keyCode)

• public String getKeyName(int

keyCode)

• public int getKeyCode(int

gameAction)

Example MIDlet : TestLowLevelEvent.java

Page 14: 13 Low 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.