📄 ui_ex4.java
字号:
// 程序名UI_Ex4.java
// 把Displayable设置为后台运行
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class UI_Ex4 extends MIDlet implements CommandListener {
private Display display; // 引用MIDlet的Display 对象
private TextBox textBox; // textBox是一个Displayable对象
private Command cmdExit; // 设定按钮用于退出MIDlet
private Command cmdNull; // 设置按钮用于触发把Displayable设置为后台的动作
// MIDlet构造程序
public UI_Ex4() {
display = Display.getDisplay(this);// 获取一个Display实例,它是唯一的
cmdExit = new Command("Exit", Command.SCREEN, 1);
cmdNull = new Command("Null", Command.SCREEN, 1);
textBox = new TextBox("UI_Ex4 Test", "Test the Displayable in background", 50, 0);
textBox.addCommand(cmdExit);// 为Displayable对象添加一个Command对象
textBox.addCommand(cmdNull);// 为Displayable对象添加一个Command对象
textBox.setCommandListener(this);// 为Displayable对象添加事件监听器
}
// 被应用程序管理器调用来启动MIDlet。
public void startApp() {
display.setCurrent(textBox);// 把textBox设置为当前屏幕或当前Displayable对象
}
// 一个必要的方法
public void pauseApp() {
}
// 一个必要的方法
public void destroyApp(boolean unconditional) {
}
// 设置事件触发时的动作
public void commandAction(Command c, Displayable d) {
if (c == cmdNull) {
System.out.println("**********Begin Test**********");
System.out.println("Before display.setCurrent(null) : ");
System.out.println("\tCurrent Displayable : "+display.getCurrent().toString());
System.out.println("\tCurrent Displayable is shown? "+display.getCurrent().isShown());
display.setCurrent(null);
System.out.println("After display.setCurrent(null) : ");
System.out.println("\tCurrent Displayable : "+display.getCurrent().toString());
System.out.println("\tCurrent Displayable is shown? "+display.getCurrent().isShown());
display.setCurrent(display.getCurrent());
System.out.println("display.setCurrent(display.getCurrent()) : ");
System.out.println("\tCurrent Displayable : "+display.getCurrent().toString());
System.out.println("\tCurrent Displayable is shown? "+display.getCurrent().isShown());
System.out.println("**********End Test**********");
}
if (c == cmdExit) {
destroyApp(false);
notifyDestroyed();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -