📄 addressbookmidlet.java
字号:
package ch09.section03;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class AddressBookMIDLet
extends MIDlet
implements CommandListener {
Display display = null;
List mnuMain = null;
TextBox txtAddress = null;
static final Command cmdBack = new Command("返回", Command.BACK, 0);
static final Command cmdExit = new Command("退出", Command.STOP, 3);
AddressDB dbAddress = null;
public AddressBookMIDLet() {
dbAddress = new AddressDB();
//杜撰的通讯录记录
file:
dbAddress.addAddress("张三", "东风大街10号");
dbAddress.addAddress("李四", "杏园小区10号楼");
dbAddress.addAddress("王五", "洞达界8号");
dbAddress.addAddress("刘的华", "巴黎巷13号");
dbAddress.addAddress("张刚", "和平门114号");
}
//程序启动时,加载初始化的记录
public void startApp() throws MIDletStateChangeException {
display = Display.getDisplay(this);
mnuMain = new List("地址", Choice.IMPLICIT);
int count = dbAddress.recordCount();
for (int i = 0; i < count; i++) {
mnuMain.append(dbAddress.getName(i + 1), null);
}
mnuMain.addCommand(cmdExit);
mnuMain.setCommandListener(this);
display.setCurrent(mnuMain);
}
public void pauseApp() {
display = null;
}
public void destroyApp(boolean unconditional) {
notifyDestroyed();
}
//响应按钮事件
public void commandAction(Command c, Displayable d) {
String str = c.getLabel();
if (str.equals("退出")) {
destroyApp(true);
}
else if (str.equals("返回")) {
display.setCurrent(mnuMain);
}
else {
List select = (List) display.getCurrent();
String txtSelect =
AddressDB.getName(select.getSelectedIndex() + 1) + ", " +
dbAddress.getAddress(select.getSelectedIndex() + 1);
txtAddress = new TextBox("地址", txtSelect, 255,
TextField.ANY);
txtAddress.addCommand(cmdBack);
txtAddress.setCommandListener(this);
display.setCurrent(txtAddress);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -