Gauge Tracker : Gauge « J2ME « Java Tutorial





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 J2MEGaugeTracker extends MIDlet implements ItemStateListener, CommandListener {
  private Gauge mGauge = new Gauge("GaugeTitle", true, 5, 3);

  private StringItem mStringItem = new StringItem(null, "[value]");

  public J2MEGaugeTracker() {
    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);

    form.append(mGauge);
    form.append(mStringItem);
    form.setItemStateListener(this);

    Display.getDisplay(this).setCurrent(form);
  }

  public void pauseApp() {
  }

  public void destroyApp(boolean unconditional) {
  }
}










31.15.Gauge
31.15.1.Add Gauge to a formAdd Gauge to a form
31.15.2.Use active and inactive GaugeUse active and inactive Gauge
31.15.3.new Gauge(null, false, 100, 50)new Gauge(null, false, 100, 50)
31.15.4.Gauge TrackerGauge Tracker
31.15.5.Gauge Non InteractiveGauge Non Interactive
31.15.6.Gauge InteractiveGauge Interactive