Get color from Display : Display « J2ME « Java Tutorial






Get color from Display
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.TextBox;
import javax.microedition.midlet.MIDlet;

public class J2MEcolorDetect extends MIDlet implements CommandListener {
  private Command exitCommand = new Command("exit", Command.EXIT, 1);

  private Display display;

  public J2MEcolorDetect() {
    display = Display.getDisplay(this);
  }

  public void startApp() {
    TextBox t;
    if (display.isColor())
      t = new TextBox("A", "B" + display.numColors(), 256, 0);
    else
      t = new TextBox("C", "D" + display.numColors(), 256, 0);
    t.addCommand(exitCommand);
    t.setCommandListener(this);
    display.setCurrent(t);
  }

  public void pauseApp() {
  }

  public void destroyApp(boolean unconditional) {
  }

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








31.2.Display
31.2.1.Add TextBox to DisplayAdd TextBox to Display
31.2.2.Get color from DisplayGet color from Display
31.2.3.Is it a color cell phoneIs it a color cell phone