creates a Form with two items, an interactive Gauge and a StringItem : Form « J2ME « Java Tutorial






creates a Form with two items, an interactive Gauge and a StringItem
import javax.microedition.lcdui.Display;
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 {
  private Gauge mGauge;

  private StringItem mStringItem;

  public J2MEGaugeTracker() {
    int initialValue = 5;
    mGauge = new Gauge("GaugeTitle", true, 10, initialValue);
    mStringItem = new StringItem(null, "[value]");
    itemStateChanged(mGauge);
  }

  public void itemStateChanged(Item item) {
    if (item == mGauge)
      mStringItem.setText("Value = " + mGauge.getValue());
  }

  public void startApp() {
    Form form = new Form("GaugeTracker");
    form.append(mGauge);
    form.append(mStringItem);
    form.setItemStateListener(this);

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

  public void pauseApp() {
  }

  public void destroyApp(boolean unconditional) {
  }
}








31.3.Form
31.3.1.Form demoForm demo
31.3.2.extends Form to create a new formextends Form to create a new form
31.3.3.Add controls to formAdd controls to form
31.3.4.GUI testGUI test
31.3.5.Add or remove controls from a form
31.3.6.creates a Form with two items, an interactive Gauge and a StringItemcreates a Form with two items, an interactive Gauge and a StringItem