/* Creating a date field and add alistener to the main form to capture events. Once the datefield is selected, you can change the date. When you exit the Datefield the date will be updated using itemStateChanges() */ import javax.microedition.midlet.*; import javax.microedition.lcdui.*; public class EventCapture extends MIDlet implements ItemStateListener, CommandListener { private Display display; private Form Main; private Command Exit; private DateField dfDate; // datefield declaration public EventCapture(){ display = Display.getDisplay(this); // create the date a retrieve the current date dfDate = new DateField("The Date is:", DateField.DATE); dfDate.setDate(new java.util.Date()); Exit = new Command("Exit", Command.EXIT, 1); // Create form - add command - add datefield - lesten for events Main = new Form("J2Me Date Display"); Main.addCommand(Exit); Main.append(dfDate); // capture command events Main.setCommandListener(this); // capture item events Main.setItemStateListener(this); } // start midlet public void startApp(){ display.setCurrent(Main); } public void pauseApp(){ } public void destroyApp(boolean unconditional){ } public void commandAction(Command c, Displayable s){ if (c == Exit){ destroyApp(false); notifyDestroyed(); } } public void itemStateChanged(Item item){ dfDate.setLabel("New Date is: "); } }