📄 ui_ex15.java
字号:
// 程序名UI_Ex15.java
// 测试TextBox对象中文本的编辑
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class UI_Ex15 extends MIDlet implements CommandListener {
private Display display; // 引用MIDlet的Display 对象
private TextBox textBox; // 声明一个TextBox对象
private Command cmdExit; // 设定按钮用于退出MIDlet
private Command cmdInsert;
// MIDlet构造程序
public UI_Ex15() {
display = Display.getDisplay(this);// 获取一个Display实例,它是唯一的
cmdExit = new Command("Exit", Command.SCREEN, 1);
cmdInsert = new Command("Insert", Command.SCREEN, 1);
textBox = new TextBox("UI_Ex15 Test", "Test the MaxSize of TextBox", 250, 0);
textBox.addCommand(cmdExit);// 为Displayable对象添加一个Command对象
textBox.addCommand(cmdInsert);// 为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 == cmdInsert) {
char[] data =new char[textBox.size()];
textBox.getChars(data);
System.out.println("data : "+new String(data));
/*
String s = new String ("Insert string in the TextBox.");
textBox.insert(s, textBox.getCaretPosition());
*/
return;
}
if (c == cmdExit) {
destroyApp(false);
notifyDestroyed();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -