⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 editdetailinfo.java

📁 基于WINCE5.0的ARM嵌入式手机上层软件开发
💻 JAVA
字号:
/* * 查看和编辑记录 */package PhoneBook;import javax.microedition.lcdui.*;import javax.microedition.midlet.*;import javax.microedition.rms.*;/** * * @author Administrator */public class EditDetailInfo extends Form implements CommandListener {    private StringItem nameField;    private TextField mobileField;    private TextField phoneField;    private TextField emailField;    private Displayable dis;    private MIDlet mid;    private RecordStore rs = null;    private int recordID;    private static final Command saveCommand = new Command("保存", Command.OK, 2);    private static final Command backCommand = new Command("返回", Command.BACK, 3);    public EditDetailInfo(String title, Displayable dis, MIDlet mid,            RecordStore rs, String name) {        super(title);        this.dis = dis;        this.mid = mid;        this.rs = rs;        nameField = new StringItem(BookConstant.name, name);        mobileField = new TextField(BookConstant.mobile, null, 25, TextField.PHONENUMBER);        phoneField = new TextField(BookConstant.phone, null, 25, TextField.PHONENUMBER);        emailField = new TextField(BookConstant.email, null, 25, TextField.EMAILADDR);        this.append(nameField);        this.append(mobileField);        this.append(phoneField);        this.append(emailField);        RecordFilter rf = new FindFilter(name);        RecordEnumeration re = null;        try {            re = rs.enumerateRecords(rf, null, false);        } catch (Exception e) {        }        //查找成功        if (re.numRecords() > 0) {            BookAccount account = null;            try {                byte[] rec;                recordID = re.nextRecordId();                rec = rs.getRecord(recordID);                account = BookAccount.deserialize(rec);                //nameField.setString(account.getUserName());                mobileField.setString(account.getMobilePhone());                phoneField.setString(account.getPhone());                emailField.setString(account.getEmail());                account = null;                re.destroy();            } catch (Exception e) {                account = null;                System.out.println("deserialize error");            }        }        this.addCommand(saveCommand);        this.addCommand(backCommand);        this.setCommandListener(this);    }    public void commandAction(Command c, Displayable d) {        if (c == saveCommand) {            if (rs != null) {                //更新记录                BookAccount account = new BookAccount(nameField.getText(),                        mobileField.getString(), emailField.getString(),                        phoneField.getString());                try {                    byte[] rec = account.serialize();//像RMS中写入记录                    rs.setRecord(recordID, rec, 0, rec.length);                    Display.getDisplay(mid).setCurrent(dis);                } catch (Exception e) {                }            }        } else if (c == backCommand) {            Display.getDisplay(mid).setCurrent(dis);        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -