Mega Code Archive

 
Categories / Java / J2ME
 

Gauge Tracker

import javax.microedition.lcdui.Command; import javax.microedition.lcdui.CommandListener; import javax.microedition.lcdui.Display; import javax.microedition.lcdui.Displayable; import javax.microedition.lcdui.Form; import javax.microedition.lcdui.Gauge; import javax.microedition.lcdui.Item; import javax.microedition.lcdui.ItemStateListener; import javax.microedition.lcdui.StringItem; import javax.microedition.midlet.MIDlet; public class GaugeTracker extends MIDlet implements ItemStateListener, CommandListener {   private Gauge mGauge = new Gauge("GaugeTitle", true, 5, 3);   private StringItem mStringItem = new StringItem(null, "[value]");   public GaugeTracker() {     itemStateChanged(mGauge);   }   public void itemStateChanged(Item item) {     if (item == mGauge)       mStringItem.setText("Value = " + mGauge.getValue());   }   public void commandAction(Command c, Displayable s) {     if (c.getCommandType() == Command.EXIT)       notifyDestroyed();   }   public void startApp() {     Form form = new Form("GaugeTracker");     form.addCommand(new Command("Exit", Command.EXIT, 0));     form.setCommandListener(this);     // Now add the selected items.     form.append(mGauge);     form.append(mStringItem);     form.setItemStateListener(this);     Display.getDisplay(this).setCurrent(form);   }   public void pauseApp() {   }   public void destroyApp(boolean unconditional) {   } }