Java Tutorial/J2ME/Display — различия между версиями

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

Текущая версия на 05:00, 1 июня 2010

Add TextBox to Display

import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.TextBox;
import javax.microedition.midlet.MIDlet;
public class TextBoxHelloMidlet extends MIDlet {
  private Display display;
  TextBox box = new TextBox("Simple Example", "Hello World", 20, 0);
  public void startApp() {
    display = Display.getDisplay(this);
    display.setCurrent(box);
  }
  public void pauseApp() {
  }
  public void destroyApp(boolean unconditional) {
  }
}





Get color from Display

import javax.microedition.lcdui.rumand;
import javax.microedition.lcdui.rumandListener;
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();
    }
  }
}





Is it a color cell phone

import javax.microedition.lcdui.rumand;
import javax.microedition.lcdui.rumandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.TextBox;
import javax.microedition.midlet.MIDlet;
public class J2MECheckColor extends MIDlet implements CommandListener {
  private Display display;
  private Form form;
  private TextBox textbox;
  private Command exit = new Command("Exit", Command.SCREEN, 1);
  public J2MECheckColor() {
    display = Display.getDisplay(this);
    String message = null;
    if (display.isColor()) {
      message = "Color display.";
    } else {
      message = "No color display";
    }
    textbox = new TextBox("Check Colors", message, 17, 0);
    textbox.addCommand(exit);
    textbox.setCommandListener(this);
  }
  public void startApp() {
    display.setCurrent(textbox);
  }
  public void pauseApp() {
  }
  public void destroyApp(boolean unconditional) {
  }
  public void commandAction(Command command, Displayable displayable) {
    if (command == exit) {
      destroyApp(true);
      notifyDestroyed();
    }
  }
}