package com.brj.test;
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.lcdui.TextField;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
/**
* 测试手机是否支持彩色. 重点练习Display的两个方法:isColor 和 numColors
*
* @author brj
*
*/
public class TestEquipmentColor extends MIDlet implements CommandListener {
private Display display;// 显示对象
private Command exitCommand;// 推出按钮
private Command showIsColor;// 是否支持彩色
private Command showColors;// 支持到少种颜色
private TextBox mainFace;// 主界面
public TestEquipmentColor() {
display = Display.getDisplay(this);
exitCommand = new Command("Exit", Command.EXIT, 0);
showIsColor = new Command("ShowIsColor", Command.SCREEN, 1);
showColors = new Command("ShowColors", Command.SCREEN, 1);
mainFace = new TextBox("Welcome", "Please Choose", 20, TextField.ANY);
}
protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
// 销毁
}
protected void pauseApp() {
// 暂停
}
protected void startApp() throws MIDletStateChangeException {
mainFace.addCommand(exitCommand);
mainFace.addCommand(showIsColor);
mainFace.addCommand(showColors);
mainFace.setCommandListener(this);
// 设置监听
display.setCurrent(mainFace);
// 设置当前显示的display对象
}
public void commandAction(Command c, Displayable d) {
if (c == exitCommand) {
try {
this.destroyApp(false);
} catch (MIDletStateChangeException e) {
e.printStackTrace();
}
this.notifyDestroyed();
}
if (c == showIsColor) {
mainFace.setString("是否支持彩色: " + display.isColor());
display.setCurrent(mainFace);
}
if (c == showColors) {
mainFace.setString("支持色彩种类:" + display.numColors());
display.setCurrent(mainFace);
}
}
}