SlideShare a Scribd company logo
1 of 27
Download to read offline
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 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.
Scenario
Listener
• Before MIDlet can accept and process an
  event, it must implements Listener
  interfaces.

• There are 2 Listeners in MIDP :
  1. CommandListener
  2. ItemStateListener
public class TestCommandListener
  extends MIDlet implements
  CommandListener {
  ...
  public void commandAction(Command c,
  Displayable s) {…}
}
public class TestItemStateListener
  extends MIDlet implements
  ItemStateListener {
  ...
  public void itemStateChanged(Item
  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 Command to a Form, Textbox,
   List or Canvas.
3. Add a "listener" to the above Form,
   Textbox, etc.
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);
}
…
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.
StringItem & ImageItem
• StringItem and ImageItem are also
  subclasses of Item however once
  allocated, these objects are static and thus
  do not receive/acknowledge events.
Command




1. Label
2. Type
3. 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 display.
Command Types
Command & CommandListener API
Item
• Item is any component that can be added
  to the form.

• ChoiceGroup, CustomItem, DateField,
  Gauge, ImageItem, Spacer, StringItem,
  TextField.
ItemListener
• When an item’s value changed, it will
  generate an item event and sent it to
  ItemListener. (Except for StringItem and
  ImageItem)
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.
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 = {
               "Info",
               "Confirmation",
               "Warning",
               "Alarm",
               "Error“
};
...
lsHero = new List("Message Type",
          List.IMPLICIT, sound, null);
lsHero.setSelectCommand(cmOpen);
lsHero.setCommandListener(this);
...
public void commandAction(Command arg0,
     Displayable arg1) {
     if(arg0 == cmOpen){
        System.out.println(“Open selected");
        System.out.println(
           ((List)arg1)
                .getString(((List)arg1)
                .getSelectedIndex())
        );
     }
}
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.

More Related Content

What's hot

Chapter 11.5
Chapter 11.5Chapter 11.5
Chapter 11.5
sotlsoc
 
Ordenar vectores
Ordenar vectoresOrdenar vectores
Ordenar vectores
ecasteloc
 
Ordenar vector
Ordenar vectorOrdenar vector
Ordenar vector
ecasteloc
 
Chapter11 graphical components
Chapter11 graphical componentsChapter11 graphical components
Chapter11 graphical components
Arifa Fatima
 
Laboratory activity 3 b2
Laboratory activity 3 b2Laboratory activity 3 b2
Laboratory activity 3 b2
Jomel Penalba
 
5.state diagrams
5.state diagrams5.state diagrams
5.state diagrams
APU
 

What's hot (20)

Event Handling in Java
Event Handling in JavaEvent Handling in Java
Event Handling in Java
 
Ajp notes-chapter-03
Ajp notes-chapter-03Ajp notes-chapter-03
Ajp notes-chapter-03
 
What is Event
What is EventWhat is Event
What is Event
 
Lesson 07 Actions and Commands in WPF
Lesson 07 Actions and Commands in WPFLesson 07 Actions and Commands in WPF
Lesson 07 Actions and Commands in WPF
 
Chapter 11.5
Chapter 11.5Chapter 11.5
Chapter 11.5
 
Events1
Events1Events1
Events1
 
File Handling
File HandlingFile Handling
File Handling
 
Dr Jammi Ashok - Introduction to Java Material (OOPs)
 Dr Jammi Ashok - Introduction to Java Material (OOPs) Dr Jammi Ashok - Introduction to Java Material (OOPs)
Dr Jammi Ashok - Introduction to Java Material (OOPs)
 
Advance java for bscit
Advance java for bscitAdvance java for bscit
Advance java for bscit
 
State Diagram
State DiagramState Diagram
State Diagram
 
behavioral model (DFD & state diagram)
behavioral model (DFD & state diagram)behavioral model (DFD & state diagram)
behavioral model (DFD & state diagram)
 
Java gui event
Java gui eventJava gui event
Java gui event
 
Ordenar vectores
Ordenar vectoresOrdenar vectores
Ordenar vectores
 
Ordenar vector
Ordenar vectorOrdenar vector
Ordenar vector
 
Seminar State Chart1
Seminar State Chart1Seminar State Chart1
Seminar State Chart1
 
Chapter11 graphical components
Chapter11 graphical componentsChapter11 graphical components
Chapter11 graphical components
 
Trabajo de case
Trabajo de caseTrabajo de case
Trabajo de case
 
Laboratory activity 3 b2
Laboratory activity 3 b2Laboratory activity 3 b2
Laboratory activity 3 b2
 
Trabajo de case
Trabajo de caseTrabajo de case
Trabajo de case
 
5.state diagrams
5.state diagrams5.state diagrams
5.state diagrams
 

Similar to 12 High Level UI Event Handling

Android webinar class_3
Android webinar class_3Android webinar class_3
Android webinar class_3
Edureka!
 
openFrameworks 007 - events
openFrameworks 007 - eventsopenFrameworks 007 - events
openFrameworks 007 - events
roxlu
 

Similar to 12 High Level UI Event Handling (20)

Session4 J2ME Mobile Information Device Profile(MIDP) Events
Session4 J2ME Mobile Information Device Profile(MIDP) EventsSession4 J2ME Mobile Information Device Profile(MIDP) Events
Session4 J2ME Mobile Information Device Profile(MIDP) Events
 
7java Events
7java Events7java Events
7java Events
 
JAVA PROGRAMMING- GUI Programming with Swing - The Swing Buttons
JAVA PROGRAMMING- GUI Programming with Swing - The Swing ButtonsJAVA PROGRAMMING- GUI Programming with Swing - The Swing Buttons
JAVA PROGRAMMING- GUI Programming with Swing - The Swing Buttons
 
B2. activity and intent
B2. activity and intentB2. activity and intent
B2. activity and intent
 
event-handling.pptx
event-handling.pptxevent-handling.pptx
event-handling.pptx
 
Nokia Asha App Development - Part 2
Nokia Asha App Development - Part 2Nokia Asha App Development - Part 2
Nokia Asha App Development - Part 2
 
Unit 6 Java
Unit 6 JavaUnit 6 Java
Unit 6 Java
 
engineeringdsgtnotesofunitfivesnists.ppt
engineeringdsgtnotesofunitfivesnists.pptengineeringdsgtnotesofunitfivesnists.ppt
engineeringdsgtnotesofunitfivesnists.ppt
 
Java-Events
Java-EventsJava-Events
Java-Events
 
event-handling.pptx
event-handling.pptxevent-handling.pptx
event-handling.pptx
 
09events
09events09events
09events
 
Android webinar class_3
Android webinar class_3Android webinar class_3
Android webinar class_3
 
Androd Listeners
Androd ListenersAndrod Listeners
Androd Listeners
 
IoT in salsa Serverless
IoT in salsa ServerlessIoT in salsa Serverless
IoT in salsa Serverless
 
Module3.11.pptx
Module3.11.pptxModule3.11.pptx
Module3.11.pptx
 
unit3.pptx
unit3.pptxunit3.pptx
unit3.pptx
 
openFrameworks 007 - events
openFrameworks 007 - eventsopenFrameworks 007 - events
openFrameworks 007 - events
 
Swing
SwingSwing
Swing
 
Awt event
Awt eventAwt event
Awt event
 
Module 5.pptx
Module 5.pptxModule 5.pptx
Module 5.pptx
 

More from corneliuskoo (15)

Basic JSTL
Basic JSTLBasic JSTL
Basic JSTL
 
Expression Language in JSP
Expression Language in JSPExpression Language in JSP
Expression Language in JSP
 
JSP
JSPJSP
JSP
 
Html Hands On
Html Hands OnHtml Hands On
Html Hands On
 
13 Low Level UI Event Handling
13 Low Level UI Event Handling13 Low Level UI Event Handling
13 Low Level UI Event Handling
 
09 Display
09 Display09 Display
09 Display
 
08 Midlet Basic
08 Midlet Basic08 Midlet Basic
08 Midlet Basic
 
07 Midlet On The Web
07 Midlet On The Web07 Midlet On The Web
07 Midlet On The Web
 
06 Eclipse ME
06 Eclipse ME06 Eclipse ME
06 Eclipse ME
 
05 J2ME Wtk Command Line
05 J2ME Wtk Command Line05 J2ME Wtk Command Line
05 J2ME Wtk Command Line
 
04 J2ME Wireless Tool Kit
04 J2ME Wireless Tool Kit04 J2ME Wireless Tool Kit
04 J2ME Wireless Tool Kit
 
03 midp
03 midp03 midp
03 midp
 
02a cldc property support
02a cldc property support02a cldc property support
02a cldc property support
 
02 cldc
02 cldc02 cldc
02 cldc
 
01 java 2 micro edition
01 java 2 micro edition01 java 2 micro edition
01 java 2 micro edition
 

Recently uploaded

Jual Obat Aborsi ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan Cytotec
Jual Obat Aborsi ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan CytotecJual Obat Aborsi ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan Cytotec
Jual Obat Aborsi ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan Cytotec
ZurliaSoop
 

Recently uploaded (20)

Falcon Invoice Discounting: Empowering Your Business Growth
Falcon Invoice Discounting: Empowering Your Business GrowthFalcon Invoice Discounting: Empowering Your Business Growth
Falcon Invoice Discounting: Empowering Your Business Growth
 
Lundin Gold - Q1 2024 Conference Call Presentation (Revised)
Lundin Gold - Q1 2024 Conference Call Presentation (Revised)Lundin Gold - Q1 2024 Conference Call Presentation (Revised)
Lundin Gold - Q1 2024 Conference Call Presentation (Revised)
 
HomeRoots Pitch Deck | Investor Insights | April 2024
HomeRoots Pitch Deck | Investor Insights | April 2024HomeRoots Pitch Deck | Investor Insights | April 2024
HomeRoots Pitch Deck | Investor Insights | April 2024
 
How to Get Started in Social Media for Art League City
How to Get Started in Social Media for Art League CityHow to Get Started in Social Media for Art League City
How to Get Started in Social Media for Art League City
 
CROSS CULTURAL NEGOTIATION BY PANMISEM NS
CROSS CULTURAL NEGOTIATION BY PANMISEM NSCROSS CULTURAL NEGOTIATION BY PANMISEM NS
CROSS CULTURAL NEGOTIATION BY PANMISEM NS
 
Falcon Invoice Discounting: The best investment platform in india for investors
Falcon Invoice Discounting: The best investment platform in india for investorsFalcon Invoice Discounting: The best investment platform in india for investors
Falcon Invoice Discounting: The best investment platform in india for investors
 
Phases of Negotiation .pptx
 Phases of Negotiation .pptx Phases of Negotiation .pptx
Phases of Negotiation .pptx
 
Horngren’s Cost Accounting A Managerial Emphasis, Canadian 9th edition soluti...
Horngren’s Cost Accounting A Managerial Emphasis, Canadian 9th edition soluti...Horngren’s Cost Accounting A Managerial Emphasis, Canadian 9th edition soluti...
Horngren’s Cost Accounting A Managerial Emphasis, Canadian 9th edition soluti...
 
Lucknow Housewife Escorts by Sexy Bhabhi Service 8250092165
Lucknow Housewife Escorts  by Sexy Bhabhi Service 8250092165Lucknow Housewife Escorts  by Sexy Bhabhi Service 8250092165
Lucknow Housewife Escorts by Sexy Bhabhi Service 8250092165
 
GUWAHATI 💋 Call Girl 9827461493 Call Girls in Escort service book now
GUWAHATI 💋 Call Girl 9827461493 Call Girls in  Escort service book nowGUWAHATI 💋 Call Girl 9827461493 Call Girls in  Escort service book now
GUWAHATI 💋 Call Girl 9827461493 Call Girls in Escort service book now
 
Berhampur CALL GIRL❤7091819311❤CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDING
Berhampur CALL GIRL❤7091819311❤CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDINGBerhampur CALL GIRL❤7091819311❤CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDING
Berhampur CALL GIRL❤7091819311❤CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDING
 
Jual Obat Aborsi ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan Cytotec
Jual Obat Aborsi ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan CytotecJual Obat Aborsi ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan Cytotec
Jual Obat Aborsi ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan Cytotec
 
SEO Case Study: How I Increased SEO Traffic & Ranking by 50-60% in 6 Months
SEO Case Study: How I Increased SEO Traffic & Ranking by 50-60%  in 6 MonthsSEO Case Study: How I Increased SEO Traffic & Ranking by 50-60%  in 6 Months
SEO Case Study: How I Increased SEO Traffic & Ranking by 50-60% in 6 Months
 
Pre Engineered Building Manufacturers Hyderabad.pptx
Pre Engineered  Building Manufacturers Hyderabad.pptxPre Engineered  Building Manufacturers Hyderabad.pptx
Pre Engineered Building Manufacturers Hyderabad.pptx
 
Uneak White's Personal Brand Exploration Presentation
Uneak White's Personal Brand Exploration PresentationUneak White's Personal Brand Exploration Presentation
Uneak White's Personal Brand Exploration Presentation
 
Durg CALL GIRL ❤ 82729*64427❤ CALL GIRLS IN durg ESCORTS
Durg CALL GIRL ❤ 82729*64427❤ CALL GIRLS IN durg ESCORTSDurg CALL GIRL ❤ 82729*64427❤ CALL GIRLS IN durg ESCORTS
Durg CALL GIRL ❤ 82729*64427❤ CALL GIRLS IN durg ESCORTS
 
JAJPUR CALL GIRL ❤ 82729*64427❤ CALL GIRLS IN JAJPUR ESCORTS
JAJPUR CALL GIRL ❤ 82729*64427❤ CALL GIRLS IN JAJPUR  ESCORTSJAJPUR CALL GIRL ❤ 82729*64427❤ CALL GIRLS IN JAJPUR  ESCORTS
JAJPUR CALL GIRL ❤ 82729*64427❤ CALL GIRLS IN JAJPUR ESCORTS
 
Paradip CALL GIRL❤7091819311❤CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDING
Paradip CALL GIRL❤7091819311❤CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDINGParadip CALL GIRL❤7091819311❤CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDING
Paradip CALL GIRL❤7091819311❤CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDING
 
Chennai Call Gril 80022//12248 Only For Sex And High Profile Best Gril Sex Av...
Chennai Call Gril 80022//12248 Only For Sex And High Profile Best Gril Sex Av...Chennai Call Gril 80022//12248 Only For Sex And High Profile Best Gril Sex Av...
Chennai Call Gril 80022//12248 Only For Sex And High Profile Best Gril Sex Av...
 
joint cost.pptx COST ACCOUNTING Sixteenth Edition ...
joint cost.pptx  COST ACCOUNTING  Sixteenth Edition                          ...joint cost.pptx  COST ACCOUNTING  Sixteenth Edition                          ...
joint cost.pptx COST ACCOUNTING Sixteenth Edition ...
 

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) {…} }
  • 7. public class TestItemStateListener extends MIDlet implements ItemStateListener { ... public void itemStateChanged(Item item) {} }
  • 8. Command Object • Command object is an object that holds information about an event.
  • 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.
  • 14. label • Specifies the text you would associate with the text.
  • 15. type • Specify the type of specific soft button.
  • 16. priority • Used by application manager when arranging items that appear in a menu or for ordering soft buttons on the display.
  • 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.
  • 22. Item & ItemListener API Item ItemListener
  • 23. List Select Command • We can change the select command for List and set it to our own command.
  • 24. private List lsHero; private Command cmOpen = new Command(“Open",Command.ITEM,1); private String[] sound = { "Info", "Confirmation", "Warning", "Alarm", "Error“ };
  • 25. ... lsHero = new List("Message Type", List.IMPLICIT, sound, null); lsHero.setSelectCommand(cmOpen); lsHero.setCommandListener(this); ...
  • 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. 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.