📄 ui_ex5.java
字号:
// 程序名UI_Ex5.java
// 把获取设备信息:色彩
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class UI_Ex5 extends MIDlet implements CommandListener {
private Display display; // 引用MIDlet的Display 对象
private TextBox textBox; // textBox是一个Displayable对象
private Command cmdExit; // 设定按钮用于退出MIDlet
private Command cmdColor; // 设定按钮触发获取设备信息的事件
// MIDlet构造程序
public UI_Ex5() {
display = Display.getDisplay(this);
cmdExit = new Command("Exit", Command.SCREEN, 1);
cmdColor = new Command("Color", Command.SCREEN, 1);
textBox = new TextBox("Color Test", "Press the \"Color\" softbutton", 50, 0);
textBox.addCommand(cmdExit);
textBox.addCommand(cmdColor);
textBox.setCommandListener(this);
}
// 被应用程序管理器调用来启动MIDlet。
public void startApp() {
display.setCurrent(textBox);
}
// 一个必要的方法
public void pauseApp() {
}
//一个必要的方法
public void destroyApp(boolean unconditional) {
}
// 设置事件触发时的动作
public void commandAction(Command c, Displayable d) {
if (c == cmdColor) {
if (display.isColor()) {
//可选择把结果在控制台输出,也可以直接在屏幕上输出
//System.out.println("The device is "+display.numColors()+" colors");
textBox.setString("The device is "+display.numColors()+" colors");
//display.setCurrent(textBox);
} else {
//System.out.println("The device is "+display.numColors()+" graylevels");
textBox.setString("The device is "+display.numColors()+" graylevels");
display.setCurrent(textBox);
}
}
if (c == cmdExit) {
destroyApp(false);
notifyDestroyed();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -