Use ImageItem in a form : ImageItem « J2ME « Java Tutorial






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.Image;
import javax.microedition.lcdui.ImageItem;
import javax.microedition.midlet.MIDlet;

public class ImageItemMIDlet extends MIDlet implements CommandListener {

  private Command exitCommand = new Command("exit", Command.EXIT, 1);

  private ImageItem imageItem;

  private Image aImage;

  private Display display = Display.getDisplay(this);

  public ImageItemMIDlet() {
    try {
      aImage = Image.createImage("/10.png");
    } catch (Exception e) {
    }

    imageItem = new ImageItem("Java 2", aImage, ImageItem.LAYOUT_CENTER, "image");
  }

  public void startApp() {
    Form aForm = new Form("ImageItem");

    aForm.append(imageItem);

    aForm.addCommand(exitCommand);

    aForm.setCommandListener(this);
    display.setCurrent(aForm);
  }

  public void pauseApp() {
  }

  public void destroyApp(boolean unconditional) {
  }

  public void commandAction(Command c, Displayable s) {
    if (c == exitCommand) {
      destroyApp(false);
      notifyDestroyed();
    }
  }
}








31.16.ImageItem
31.16.1.ImageItem with Image layout center
31.16.2.ImageItem with image layout left
31.16.3.ImageItem with image layout right
31.16.4.ImageItem with default image layout
31.16.5.Combine ImageItem.LAYOUT_NEWLINE_BEFORE, ImageItem.LAYOUT_CENTER,ImageItem.LAYOUT_NEWLINE_AFTER for ImageItem
31.16.6.Load png image to ImageItem
31.16.7.Use ImageItem in a form