Your SlideShare is downloading. ×
0
High Level UI Components Event Handling           Cornelius Koo - 2005
What is Event Handling• Process of recognizing when an event  occurs and taking an action based on that  event.
3 Steps in Event Management1.The hardware must recognize that something  has occured : button pressed, mouse clicked,  mou...
Scenario
Listener• Before MIDlet can accept and process an  event, it must implements Listener  interfaces.• There are 2 Listeners ...
public class TestCommandListener  extends MIDlet implements  CommandListener {  ...  public void commandAction(Command c, ...
public class TestItemStateListener  extends MIDlet implements  ItemStateListener {  ...  public void itemStateChanged(Item...
Command Object• Command object is an object that holds  information about an event.
Processing Events• Processing events steps :1. Create a Command object to hold   information about an event.2. Add the Com...
private Display display;private Command cmExit;private Form fmMain;public TestDisplayable() {    super();    display = Dis...
Item Object• Any components that can be added to a  Form.• ChoiceGroup, DateField, Gauge and  TextField are all subclasses...
StringItem & ImageItem• StringItem and ImageItem are also  subclasses of Item however once  allocated, these objects are s...
Command1. Label2. Type3. Priority
label• Specifies the text you would associate with  the text.
type• Specify the type of specific soft button.
priority• Used by application manager when  arranging items that appear in a menu or  for ordering soft buttons on the dis...
Command Types
Command & CommandListener API
Item• Item is any component that can be added  to the form.• ChoiceGroup, CustomItem, DateField,  Gauge, ImageItem, Spacer...
ItemListener• When an item’s value changed, it will  generate an item event and sent it to  ItemListener. (Except for Stri...
When it is called ?• If an Item has changed, itemStateChanged() must be  called for the changed Item before it will  ackno...
Item & ItemListener API  Item  ItemListener
List Select Command• We can change the select command for  List and set it to our own command.
private List lsHero;private Command cmOpen = new     Command(“Open",Command.ITEM,1);private String[] sound = {            ...
...lsHero = new List("Message Type",          List.IMPLICIT, sound, null);lsHero.setSelectCommand(cmOpen);lsHero.setComman...
public void commandAction(Command arg0,     Displayable arg1) {     if(arg0 == cmOpen){        System.out.println(“Open se...
Reference• Core J2ME Technology and MIDP. John  W. Muchow. Prentice Hall PTR, 2002.• Enterprise J2ME: Developing Mobile  J...
Upcoming SlideShare
Loading in...5
×

12 High Level UI Event Handling

1,489

Published on

Published in: Business, Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
1,489
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
25
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Transcript of "12 High Level UI Event Handling"

  1. 1. High Level UI Components Event Handling Cornelius Koo - 2005
  2. 2. What is Event Handling• Process of recognizing when an event occurs and taking an action based on that event.
  3. 3. 3 Steps in Event Management1.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.
  4. 4. Scenario
  5. 5. Listener• Before MIDlet can accept and process an event, it must implements Listener interfaces.• There are 2 Listeners in MIDP : 1. CommandListener 2. ItemStateListener
  6. 6. public class TestCommandListener extends MIDlet implements CommandListener { ... public void commandAction(Command c, Displayable s) {…}}
  7. 7. public class TestItemStateListener extends MIDlet implements ItemStateListener { ... public void itemStateChanged(Item item) {}}
  8. 8. Command Object• Command object is an object that holds information about an event.
  9. 9. 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.
  10. 10. 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);}…
  11. 11. 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.
  12. 12. StringItem & ImageItem• StringItem and ImageItem are also subclasses of Item however once allocated, these objects are static and thus do not receive/acknowledge events.
  13. 13. Command1. Label2. Type3. Priority
  14. 14. label• Specifies the text you would associate with the text.
  15. 15. type• Specify the type of specific soft button.
  16. 16. priority• Used by application manager when arranging items that appear in a menu or for ordering soft buttons on the display.
  17. 17. Command Types
  18. 18. Command & CommandListener API
  19. 19. Item• Item is any component that can be added to the form.• ChoiceGroup, CustomItem, DateField, Gauge, ImageItem, Spacer, StringItem, TextField.
  20. 20. ItemListener• When an item’s value changed, it will generate an item event and sent it to ItemListener. (Except for StringItem and ImageItem)
  21. 21. 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.
  22. 22. Item & ItemListener API Item ItemListener
  23. 23. List Select Command• We can change the select command for List and set it to our own command.
  24. 24. private List lsHero;private Command cmOpen = new Command(“Open",Command.ITEM,1);private String[] sound = { "Info", "Confirmation", "Warning", "Alarm", "Error“};
  25. 25. ...lsHero = new List("Message Type", List.IMPLICIT, sound, null);lsHero.setSelectCommand(cmOpen);lsHero.setCommandListener(this);...
  26. 26. public void commandAction(Command arg0, Displayable arg1) { if(arg0 == cmOpen){ System.out.println(“Open selected"); System.out.println( ((List)arg1) .getString(((List)arg1) .getSelectedIndex()) ); }}
  27. 27. 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.
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×