Form demo : Form « J2ME « Java Tutorial






Form demo
import javax.microedition.lcdui.Choice;
import javax.microedition.lcdui.ChoiceGroup;
import javax.microedition.lcdui.DateField;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Gauge;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.ImageItem;
import javax.microedition.lcdui.StringItem;
import javax.microedition.lcdui.TextField;
import javax.microedition.midlet.MIDlet;

public class J2MEFormDemo extends MIDlet {
  Display d;

  Form aForm = new Form("Demo Form");

  ChoiceGroup aChoiceGroup = new ChoiceGroup("Choose", Choice.EXCLUSIVE, new String[] { "This",
      "That" }, null);

  DateField aDateField = new DateField(null, DateField.TIME);

  Gauge aGauge = new Gauge("Score", true, 10, 1);

  StringItem aStringItem = new StringItem(null, "Demo Items");

  TextField aTextField = new TextField("Comments", "Your comments here", 20, 0);

  ImageItem anImageItem;

  Image anImage;

  public J2MEFormDemo() {
    try {
      anImage = Image.createImage("/star.png");
    } catch (java.io.IOException ioE) {
      System.out.println("Problem reading image");
    }
    anImageItem = new ImageItem("Demo Image", anImage, ImageItem.LAYOUT_CENTER, "No image");
    aForm.append(aStringItem);
    aForm.append(aChoiceGroup);
    aForm.append(aDateField);
    aForm.append(aGauge);
    aForm.append(aTextField);
    aForm.append(anImageItem);
  }

  protected void startApp() {
    d = Display.getDisplay(this);
    d.setCurrent(aForm);
  }

  protected void pauseApp() {
  }

  protected 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