import javax.microedition.midlet.*;import javax.microedition.lcdui.*; public class AddressBookMIDLet extends MIDlet implementsCommandListener { Display display = null; List mnuMain = null; TextBox txtAddress = null; static final Command cmdBack = new Command("Back", Command.BACK,0); static final Command cmdExit = new Command("Exit", Command.STOP,3); AddressDB dbAddress = null; public AddressBookMIDLet() { dbAddress = new AddressDB(); file://杜撰的地址 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("Exit")) { destroyApp(true); } else if (str.equals("Back")) { display.setCurrent(mnuMain); } else { List select = (List)display.getCurrent(); String txtSelect = AddressDB.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); } } } |
四、本节小结
在本例子中,我示范如何使用 J2ME记录管理系统(RMS)构造一个基本的通讯录应用程序,支持局部数据存储的能力是 J2ME与其他无线技术比如 WML/WMLScript的不同之处,当然,要使来自移动设备的数据与一个企业数据库同步需要附加的网络和输入/输出性能,下面我想谈谈J2ME网络功能。
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |