Chandigarh Escorts Service 📞8868886958📞 Just📲 Call Nihal Chandigarh Call Girl...
12 High Level UI Event Handling
1. High Level UI Components
Event Handling
Cornelius Koo - 2005
2. What is Event Handling
• Process of recognizing when an event
occurs and taking an action based on that
event.
3. 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.
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. public class TestCommandListener
extends MIDlet implements
CommandListener {
...
public void commandAction(Command c,
Displayable s) {…}
}
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. 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. 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. StringItem & ImageItem
• StringItem and ImageItem are also
subclasses of Item however once
allocated, these objects are static and thus
do not receive/acknowledge events.
19. Item
• Item is any component that can be added
to the form.
• ChoiceGroup, CustomItem, DateField,
Gauge, ImageItem, Spacer, StringItem,
TextField.
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. 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.
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.