Java by API/javax.microedition.lcdui/List — различия между версиями

Материал из Java эксперт
Перейти к: навигация, поиск
м (1 версия)
 
м (1 версия)
 
(нет различий)

Текущая версия на 14:49, 31 мая 2010

List: append(String stringPart, Image imagePart)

 
import javax.microedition.lcdui.Choice;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.List;
import javax.microedition.midlet.MIDlet;
public class PaymentMIDlet extends MIDlet {
  private Display display;
  List options = new List("Method of Payment", Choice.EXCLUSIVE);
  public void startApp() {
    display = Display.getDisplay(this);
    options.append("Visa", null);
    options.append("MasterCard", null);
    options.append("Amex", null);
    display.setCurrent(options);
  }
  public void pauseApp() {
  }
  public void destroyApp(boolean unconditional) {
  }
}





List.SELECT_COMMAND

 

import java.io.IOException;
import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.AlertType;
import javax.microedition.lcdui.rumand;
import javax.microedition.lcdui.rumandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.List;
import javax.microedition.midlet.MIDlet;
public class J2METravelList extends MIDlet implements CommandListener {
  private List mList;
  private Command mExitCommand, mNextCommand;
  public J2METravelList() {
    String[] stringElements = { "A", "C", "H" };
    Image[] imageElements = { loadImage("/a.png"), loadImage("/c.png"),
        loadImage("/h.png") };
    mList = new List("Reservation type", List.IMPLICIT, stringElements, imageElements);
    mNextCommand = new Command("Next", Command.SCREEN, 0);
    mExitCommand = new Command("Exit", Command.EXIT, 0);
    mList.addCommand(mNextCommand);
    mList.addCommand(mExitCommand);
    mList.setCommandListener(this);
  }
  public void startApp() {
    Display.getDisplay(this).setCurrent(mList);
  }
  public void commandAction(Command c, Displayable s) {
    if (c == mNextCommand || c == List.SELECT_COMMAND) {
      int index = mList.getSelectedIndex();
      Alert alert = new Alert("Your selection", "You chose " + mList.getString(index) + ".", null,
          AlertType.INFO);
      Display.getDisplay(this).setCurrent(alert, mList);
    } else if (c == mExitCommand)
      notifyDestroyed();
  }
  public void pauseApp() {
  }
  public void destroyApp(boolean unconditional) {
  }
  private Image loadImage(String name) {
    Image image = null;
    try {
      image = Image.createImage(name);
    } catch (IOException ioe) {
      System.out.println(ioe);
    }
    return image;
  }
}





new List(String title, int listType, String[] stringElements, Image[] imageElements)

 

import java.io.IOException;
import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.AlertType;
import javax.microedition.lcdui.rumand;
import javax.microedition.lcdui.rumandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.List;
import javax.microedition.midlet.MIDlet;
public class J2METravelList extends MIDlet implements CommandListener {
  private List mList;
  private Command mExitCommand, mNextCommand;
  public J2METravelList() {
    String[] stringElements = { "A", "C", "H" };
    Image[] imageElements = { loadImage("/a.png"), loadImage("/c.png"),
        loadImage("/h.png") };
    mList = new List("Reservation type", List.IMPLICIT, stringElements, imageElements);
    mNextCommand = new Command("Next", Command.SCREEN, 0);
    mExitCommand = new Command("Exit", Command.EXIT, 0);
    mList.addCommand(mNextCommand);
    mList.addCommand(mExitCommand);
    mList.setCommandListener(this);
  }
  public void startApp() {
    Display.getDisplay(this).setCurrent(mList);
  }
  public void commandAction(Command c, Displayable s) {
    if (c == mNextCommand || c == List.SELECT_COMMAND) {
      int index = mList.getSelectedIndex();
      Alert alert = new Alert("Your selection", "You chose " + mList.getString(index) + ".", null,
          AlertType.INFO);
      Display.getDisplay(this).setCurrent(alert, mList);
    } else if (c == mExitCommand)
      notifyDestroyed();
  }
  public void pauseApp() {
  }
  public void destroyApp(boolean unconditional) {
  }
  private Image loadImage(String name) {
    Image image = null;
    try {
      image = Image.createImage(name);
    } catch (IOException ioe) {
      System.out.println(ioe);
    }
    return image;
  }
}