📄 findrecord.java
字号:
/* * To change this template, choose Tools | Templates * and open the template in the editor. */package PhoneBook;import java.io.*;import javax.microedition.io.*;import javax.microedition.lcdui.*;import javax.microedition.midlet.*;import javax.microedition.rms.RecordEnumeration;import javax.microedition.rms.RecordFilter;import javax.microedition.rms.RecordStore;/** * * @author Administrator */public class FindRecord extends Form implements CommandListener{ private Displayable dis; private MIDlet mid; private RecordStore rs = null; private RecordEnumeration re = null; private static final Command findCommand = new Command("查找", Command.OK, 1); private static final Command backCommand = new Command("返回", Command.BACK,2); //private RecordEnumeration re = null; private TextField tf; public FindRecord(Displayable dis,MIDlet mid,RecordStore rs) { super("查询记录"); tf = new TextField("输入名字",null, 120,TextField.ANY); //设置控件的布局 tf.setLayout(Item.LAYOUT_NEWLINE_AFTER); this.append(tf); this.dis = dis; this.mid = mid; this.rs = rs; this.addCommand(backCommand); this.addCommand(findCommand); this.setCommandListener(this); } public void commandAction(Command c, Displayable d) { if (c == backCommand) { Display.getDisplay(mid).setCurrent(dis); } if (c == findCommand) { RecordFilter rf = new FindFilter(tf.getString()); try { re = rs.enumerateRecords(rf, null, false); } catch (Exception e) { } //查找成功 if (re.numRecords() > 0) { BookAccount account = null; int recordID; try { byte[] rec; recordID = re.nextRecordId(); rec = rs.getRecord(recordID); account = BookAccount.deserialize(rec); StringItem name = new StringItem("姓名:",account.getUserName()); StringItem mobilePhone = new StringItem("移动电话:",account.getMobilePhone()); StringItem phone = new StringItem("家庭电话:",account.getPhone()); StringItem email = new StringItem("电子邮件:",account.getEmail()); name.setLayout(Item.LAYOUT_NEWLINE_AFTER); mobilePhone.setLayout(Item.LAYOUT_NEWLINE_AFTER); phone.setLayout(Item.LAYOUT_NEWLINE_AFTER); email.setLayout(Item.LAYOUT_NEWLINE_AFTER); this.append(name); this.append(mobilePhone); this.append(phone); this.append(email); account = null; re.destroy(); } catch (Exception e) { account = null; System.out.println("deserialize error"); } } } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -