/************************************** * Source & Further Reading: J. W. Muchow (2002), Core J2ME Technology & MIDP, Sun MICROSYSTEMS ***************************************/ // A list to provide options for configuring the timer import javax.microedition.lcdui.*; class OptionsList extends List implements CommandListener{ private AnimTimer midlet; // Main midlet private Command cmBack; // constructor public OptionsList(String title, int listType, AnimTimer midlet){ // call list constructor super(title, listType); // save refernce to MIDlet to access displaymanager this.midlet = midlet; // create list entries append("Sleep interval", null); append("Start", null); append("Stop", null); // create command and listen for events cmBack = new Command("Back", Command.BACK, 1); addCommand(cmBack); setCommandListener(this); } public void commandAction(Command c, Displayable d){ if(c == List.SELECT_COMMAND){ switch (getSelectedIndex()){ case 0: // Push current displayable and show the form to adjust timer sleep midlet.displayMgr.pushDisplayable(midlet.fmSleep); break; case 1: // start timer and retrurn to previous display midlet.cvTimer.startTimer(); midlet.displayMgr.popDisplayable(); break; case 2: // stop timer and return to previous displayable midlet.cvTimer.stopTimer(); midlet.displayMgr.popDisplayable(); break; } } else if(c == cmBack){ // return to previous displayable midlet.displayMgr.popDisplayable(); } } }