Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home J2me J2ME Item State Listener Example

Related Tutorials


 
 

Share on Google+Share on Google+

J2ME Item State Listener Example

Advertisement
In this application we are going to shows how to implement the ItemStateListener interface in the j2me midlet.

J2ME Item State Listener Example

     

In this application we are going to shows how to implement the ItemStateListener interface in the j2me midlet. The ItemStateListener interface is used by applications which need to receive events that indicate changes in the internal state of the interactive items within a Form screen. The ItemStateListener interface having only one method that is:

itemStateChanged(Item item):- This is the void type method which called when internal state of an Item has been changed by the user.

By this example you can learn the implementation of ItemStateListener in only three easy steps:

  1. In the first step we create the DateField and set the current date with this field as shown in figure.

 

 

 

 

 

 2. In the second step click on select button then the calendar will be display as shown below.  

 

 3. And finally choose the new date and click on "Save" then the new date will display on the mobile window as shown.

 

ItemStateListenerMIDlet.java

import java.util.*;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;

public class ItemStateListenerMIDlet extends MIDlet{
  private Display display;
  private Form form;
  private Date date = new Date();
  private Calendar calendar;
  private DateField today;

  public ItemStateListenerMIDlet(){
  display = Display.getDisplay(this);
  }

  public void startApp(){
  form = new Form("ItemStateListener");
  ItemStateListener listener = new ItemStateListener(){
  Calendar calendar = Calendar.getInstance(TimeZone.getDefault());

  public void itemStateChanged(Item item){
  calendar.setTime(((DateField)item).getDate());
  }
  };
  form.setItemStateListener(listener);  
  today = new DateField("Today's Date:", DateField.DATE);
  today.setDate(date);
  form.append(today);
  display.setCurrent(form);
  }

  public void pauseApp(){
  display = null;
  }

  public void destroyApp(boolean unconditional){
  notifyDestroyed();
  }
}

 

Download Source Code

Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: December 1, 2008

Related Tutorials

Discuss: J2ME Item State Listener Example   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0
DMCA.com