12 High Level UI Event Handling

1,633
-1

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,633
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
26
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

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.

×