【Java开源代码栏目提醒】:本文主要为网学会员提供AddressBookMIDLet.java,希望对需要AddressBookMIDLet.java网友有所帮助,学习一下!
package ch12;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
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);
AddressBookDB dbAddress = null;
public AddressBookMIDLet() {
dbAddress = new AddressBookDB();
//杜撰的地址
dbAddress.addAddress("Bill Gates", "123 Elm Street");
dbAddress.addAddress("George Bush", "742 Avenue B");
dbAddress.addAddress("Yuki Aka", "853 Franklin Avenue");
dbAddress.addAddress("Oba Muchow", "101 Scenic Highway");
dbAddress.addAddress("Bill Clinton", "741 Highway 101");
}
public void startApp() throws MIDletStateChangeException {
display = Display.getDisplay(this);
mnuMain = new List("Addresses", 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 =
AddressBookDB.getName(select.getSelectedIndex() + 1) + ", " +
dbAddress.getAddress(select.getSelectedIndex() + 1);
txtAddress = new TextBox("Address", txtSelect, 255,
TextField.ANY);
txtAddress.addCommand(cmdBack);
txtAddress.setCommandListener(this);
display.setCurrent(txtAddress);
}
}
}