📄 mainmidlet.java
字号:
/* * To change this template, choose Tools | Templates * and open the template in the editor. */package PhoneBook;import javax.microedition.lcdui.*;import javax.microedition.midlet.*;import javax.microedition.rms.*;/** * @author Administrator */public class MainMidlet extends MIDlet implements CommandListener { private final static Command exitCommand = new Command("退出", Command.EXIT, 1); private final static Command confirmCommand = new Command("确定", Command.SCREEN, 1); private Display display; private List mainList; private RecordStore rs; public MainMidlet() { display = Display.getDisplay(this); } public void startApp() { String[] stringArray = {"添加新记录", "浏览电话簿", "查找记录", "删除记录"}; mainList = new List("电话簿", Choice.IMPLICIT, stringArray, null); mainList.addCommand(exitCommand); mainList.addCommand(confirmCommand); mainList.setCommandListener(this); display.setCurrent(mainList); //打开记录集,如果不存在则创建 try { rs = RecordStore.openRecordStore("MyPhoneBook", true); } catch (Exception e) { rs = null; } } public void pauseApp() { } public void destroyApp(boolean unconditional) { } public void commandAction(Command c, Displayable d) { if (d.equals(mainList)) { // 如果选择了确定按钮则判断选择了哪一个列表框 if (c == List.SELECT_COMMAND || c == confirmCommand) { if (d.equals(mainList)) { switch (((List) d).getSelectedIndex()) { case 0: //添加新纪录 NewRecordForm newRF = new NewRecordForm(BookConstant.record_added, mainList, this, rs); display.setCurrent(newRF); break; case 1: //显示电话本 ListRecord list = new ListRecord(BookConstant.listPhoneTitle, Choice.IMPLICIT, mainList, this, rs); display.setCurrent(list); break; case 2: FindRecord fr = new FindRecord(mainList, this, rs); display.setCurrent(fr); break; case 3: //删除记录 DeleteRecord dr = new DeleteRecord(mainList, this, rs); display.setCurrent(dr); break; } } } } //如果键入退出按钮,则退出程序 if (c == exitCommand) { //关闭记录文件 try { rs.closeRecordStore(); rs = null; } catch (Exception e) { } destroyApp(false); notifyDestroyed(); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -