/************************************** * Source & Further Reading: J. W. Muchow (2002), Core J2ME Technology & MIDP, Sun MICROSYSTEMS ***************************************/ // Form with gauge to adjust sleep interval of timer import javax.microedition.lcdui.*; public class SleepForm extends Form implements CommandListener{ private AnimTimer midlet; // Main midlet private Command cmHome, cmBack, cmSave; // Commands private Gauge gaSleep; // gauge // constructor public SleepForm(String title, AnimTimer midlet){ // call the constructor super(title); // save refernce to midlet to access displaymanager this.midlet = midlet; // add commands cmBack = new Command("Back", Command.BACK, 2); cmSave = new Command("Save", Command.SCREEN, 1); cmHome = new Command("Home", Command.SCREEN, 2); // add gauge gaSleep = new Gauge("Timer Sleep", true, 100, 1000); // gauge holds values of 0 to 100, divide the current sleep by 10 gaSleep.setValue(midlet.cvTimer.getSleep() / 10); append (gaSleep); addCommand(cmSave); addCommand(cmHome); addCommand(cmBack); setCommandListener(this); } // event handling public void commandAction(Command c, Displayable d){ if(c == cmSave){ // Gauge returns vlaue between 0 to 100, we want miliseconds so multiply by 10 midlet.cvTimer.setSleep(gaSleep.getValue()* 10); // back to main midlet midlet.displayMgr.home(); } else if(c == cmBack){ // pop the last displayable off the stack midlet.displayMgr.popDisplayable(); } else if (c == cmHome){ midlet.displayMgr.home(); } } }