花了两天时间搞定了通讯录,基本功能能实现
现在拿出来给大家一起交流,希望大家能找出bug

截图如下




以下是代码:请保留作者版权,谢谢
//=====================messagemidlet主类=============================== package messagemidlet; //主类 import javax.microedition.midlet.*; import javax.microedition.lcdui.*; public class messagemidlet extends midlet { public static messagemidlet messagemidlet; private menumidlet menumidlet = new menumidlet(); /** constructor */ public messagemidlet() { messagemidlet = this; } /** main method */ public void startapp() { display.getdisplay(this).setcurrent(menumidlet); } /** handle pausing the midlet */ public void pauseapp() { } /** handle destroying the midlet */ public void destroyapp(boolean unconditional) { } /** quit the midlet */ public static void quitapp() { messagemidlet.destroyapp(true); messagemidlet.notifydestroyed(); messagemidlet = null; } } //=========================end================================ //=========================setget操作用到的属性================================ package messagemidlet; ///java为什么不像c#一样有get set 来设置属性,所以麻烦点,我还是喜欢c# public class setget { public static int id = 0; public static int delid = 0; public static int modid = 0; public static string str = null; public static boolean isok =true ; /** constructor */ public setget() { } public static void setid(int id){ id = id; } public static int getid(){ return id; } public static void setdelid(int id) { delid = id; } public static int getdelid() { return delid; } public static void setmodid(int id) { modid = id; } public static int getmodid() { return modid; } public static void setstr(string str){ str = str; } public static string getstr(){ return str; } public static void setistrue(boolean istrue){ isok = istrue; } public static boolean getistrue(){ return isok; } } //=========================end================================ //=========================pubclass公共类(集成一些常用属性和方法,方便调用)================================ package messagemidlet; import javax.microedition.lcdui.*; import javax.microedition.rms.*; import java.io.*; public class pubclass { public static pubclass pubclass; public display display; //舞台对象 public command exitcommand; //离开按钮对象 public command selectcommand; //选择按钮对象 public command menucommand; //主目录 public command okcommand ; public command opercommand; public string[] menulist = {'通讯录','关于作者'}; //主菜单选项 public string[] mainlist ={'浏览联系人','查找联系人','添加联系人','其他'}; public string[] operatelist={'编辑联系人','删除联系人','全部删除'}; //操作 //只需修改personpro属性,其他自动生成,构造 public string[] personpro ={'姓名','手机','email','地址','其他'}; //用户属性 public int length = personpro.length; //用户属性个数 public string dataname = 'messages'; //数据库名 public boolean existingornot = existing(dataname); recordstore rs = null; public textfield[] person = new textfield[length]; public stringitem[] persondetail = new stringitem[length]; /** 构造函数 */ public pubclass() { for(int i=0;inew textfield(personpro[i], '', 256, textfield.any); persondetail[i] = new stringitem(personpro[i],''); } } //取得主目录列表 public string get_menulist(int i){ if(this.mainlist.length<0){ return ''; } return this.menulist[i]; } //取得通讯录列表 public string get_mainlist(int j){ if(this.mainlist.length<0){ return ''; } return this.mainlist[j]; } //取得联系人操作列表 public string get_operatelist(int j){ if(this.operatelist.length<0){ return ''; } return this.operatelist[j]; } //返回关于 public void return_aboutmidlet() { aboutmidlet aboutmidlet = new aboutmidlet(); display.getdisplay(messagemidlet.messagemidlet).setcurrent(aboutmidlet); } //返回主目录 public void return_mainmidlet() { mainmidlet mainmidlet = new mainmidlet(); display.getdisplay(messagemidlet.messagemidlet).setcurrent(mainmidlet); } //返回通讯录列表 public void return_menumidlet(){ menumidlet menumidlet = new menumidlet(); display.getdisplay(messagemidlet.messagemidlet).setcurrent(menumidlet); } //返回联系人列表 public void return_personlistmidlet(){ personlistmidlet personlistmidlet = new personlistmidlet(); display.getdisplay(messagemidlet.messagemidlet).setcurrent(personlistmidlet); } //返回查找联系人 public void return_searchpersonmidlet(){ } //返回添加联系人 public void return_addpersonmidlet(){ addpersonmidlet addpersonmidlet = new addpersonmidlet(); display.getdisplay(messagemidlet.messagemidlet).setcurrent(addpersonmidlet); } //返回操作 public void return_operatemidlet(){ operatemidlet operatemidlet = new operatemidlet(); display.getdisplay(messagemidlet.messagemidlet).setcurrent(operatemidlet); } //返回查找 public void return_searchmidlet() { searchmidlet searrchmidlet = new searchmidlet(); display.getdisplay(messagemidlet.messagemidlet).setcurrent(searrchmidlet); } //返回查找结果 public void return_searchoutmidlet() { searchoutmidlet searrchoutmidlet = new searchoutmidlet(); display.getdisplay(messagemidlet.messagemidlet).setcurrent(searrchoutmidlet); } //返回编辑 public void return_modifypersonmidlet() { modifypersonmidlet modiftpersonmidlet = new modifypersonmidlet(); display.getdisplay(messagemidlet.messagemidlet).setcurrent(modiftpersonmidlet); } //返回联系人详细列表,并传入对应id值 modifypersonmidlet public void return_persondetailmidlet(){ persondetailmidlet persondetailmidlet = new persondetailmidlet(); display.getdisplay(messagemidlet.messagemidlet).setcurrent(persondetailmidlet); } //警告窗口 public void alert(string alertstring){ alert alert = new alert('提示',alertstring,createimage('/images/1.png'),alerttype.error); alert.settimeout(2000); display.getdisplay(messagemidlet.messagemidlet).setcurrent(alert); } //警告窗口,提示后返回mainmidlet public void alert(string alertstring,mainmidlet mainmidlet){ alert alert = new alert('提示',alertstring,createimage('/images/1.png'),alerttype.error); alert.settimeout(2000); display.getdisplay(messagemidlet.messagemidlet).setcurrent(alert,mainmidlet); } //警告窗口,提示后返回personlistmidlet public void alert(string alertstring, personlistmidlet personlistmidlet) { alert alert = new alert('提示', alertstring, createimage('/images/1.png'),alerttype.error); alert.settimeout(2000); display.getdisplay(messagemidlet.messagemidlet).setcurrent(alert, personlistmidlet); } //创建图像 public static image createimage(string name){ image aimage = null; try{ aimage = image.createimage(name); } catch(ioexception e){ } return aimage; } //判断数据库是否存在,打开,然会recordstore对象 public recordstore open(){ boolean existingornot = false; boolean ok = true; existingornot = this.existing(dataname); if (existingornot) { try { rs = recordstore.openrecordstore(dataname, false); } catch (exception e) { ok = false; } } else { try { rs = recordstore.openrecordstore(dataname, true); ok = true; } catch (exception e) { ok = false; } } return rs; } //判断字符大小 public boolean existing(string recordstorestring) { boolean existingornot = false; recordstore rs = null; if (recordstorestring.length() > 32) return false; try { rs = recordstore.openrecordstore(recordstorestring, false); } catch (recordstorenotfoundexception e) { existingornot = false; } catch (exception e) { } finally { try { rs.closerecordstore(); } catch (exception e) { } } return existingornot; } } //=========================end================================ //=========================personclass用户属性类================================ package messagemidlet; //联系人属性类 import java.io.*; import javax.microedition.rms.*; public class personclass { private static personclass personclass; //构造公共类实例 private pubclass pubclass = new pubclass(); public static int id = -1; //设置静态id,赋值后不需要重新构造而不能调用 //联系人属性,数组 public string[] personpro = new string[pubclass.length] ; public void write(string[] personpro){ for(int i = 0;i this.personpro[i] = personpro[i]; } } //设置id,起修改,删除,显示作用 public void setrecordid(int id){ this.id = id; } //取得id public static int getrecordid(){ return id; } //转换为字节 public byte[] changetobytearray(){ byte[] data = null; try{ bytearrayoutputstream baos = new bytearrayoutputstream(); dataoutputstream dos = new dataoutputstream(baos); for(int j=0;j<this.personpro.length;j++){ dos.writeutf(this.personpro[j]); } data = baos.tobytearray(); baos.close(); dos.close(); } catch(exception e){ return null; } return data; } public void changefrombytearray(byte[] data) { try { bytearrayinputstream bais = new bytearrayinputstream(data); datainputstream dis = new datainputstream(bais); for(int k=0;k this.personpro[k] = dis.readutf(); } bais.close(); dis.close(); } catch (exception e) { } } public string getperson(int m) { return this.personpro[m]; } public string getlistname(int recordid){ return this.personpro[0]; } } //=========================end================================ //=========================menumidlet主目录里表类================================ package messagemidlet; import javax.microedition.lcdui.*; import java.io.*; public class menumidlet extends list implements commandlistener { //构造公共类实例 private pubclass pubclass = new pubclass(); /** constructor */ public menumidlet() { super('通讯录',list.implicit); for(int i=0;i this.append(pubclass.get_menulist(i),pubclass.createimage('/images/tel.png')); } //构造按钮 pubclass.selectcommand = new command('选择', command.screen, 2); pubclass.exitcommand = new command('离开', command.exit, 1); //添加监听 this.addcommand(pubclass.exitcommand); this.addcommand(pubclass.selectcommand); this.setcommandlistener(this); } public void commandaction(command c, displayable d) { if(c == pubclass.selectcommand ){ int selectitem = this.getselectedindex(); //尽量不使用switch,用if提高速度,虽然麻烦点,经验所得 if (selectitem == 0) { pubclass.return_mainmidlet(); } if (selectitem == 1) { pubclass.return_aboutmidlet(); } } //退出 if(c == pubclass.exitcommand){ messagemidlet.quitapp(); } } } //=========================end================================ //=========================aboutmidlet关于作者类(显示作者信息)================================ package messagemidlet; import javax.microedition.midlet.*; import javax.microedition.lcdui.*; import javax.microedition.lcdui.command; import javax.microedition.lcdui.displayable; public class aboutmidlet extends form implements commandlistener { //构造公共类实例 private pubclass pubclass = new pubclass(); /** constructor */ public aboutmidlet() { super(''); this.settitle('关于作者'); stringitem stringitem = new stringitem('作者介绍','01网通(2)02号. 姓名:sukey. 版权所有:sukey.'); this.append(stringitem); //构造按钮 pubclass.menucommand = new command('主目录', command.screen, 1); pubclass.exitcommand = new command('离开', command.back, 1); //添加监听 this.addcommand(pubclass.menucommand); this.addcommand(pubclass.exitcommand); this.setcommandlistener(this); } public void commandaction(command c, displayable d) { if(c ==pubclass.menucommand ){ pubclass.return_menumidlet(); } if(c == pubclass.exitcommand){ messagemidlet.quitapp(); } } } //=========================end================================ //=========================mainmidlet通讯录里表类================================ package messagemidlet; // import javax.microedition.lcdui.*; public class mainmidlet extends list implements commandlistener { //构造公共类实例 private pubclass pubclass = new pubclass(); /** constructor */ public mainmidlet() { super('通讯录',list.implicit); //显示列表 for(int i=0;i this.append(pubclass.get_mainlist(i),pubclass.createimage('/images/tel.png')); } //构造按钮 pubclass.selectcommand = new command('选择', command.ok, 1); pubclass.menucommand = new command('主目录', command.exit, 2); //添加监听 this.addcommand(pubclass.selectcommand); this.addcommand(pubclass.menucommand); this.setcommandlistener(this); } public void commandaction(command c, displayable d) { if (c == pubclass.selectcommand) { int selectitem = this.getselectedindex(); //尽量不使用switch,用if提高速度,虽然麻烦点,经验所得 if (selectitem == 0) { pubclass.return_personlistmidlet(); } if (selectitem == 1) { pubclass.return_searchmidlet(); } if (selectitem == 2) { pubclass.return_addpersonmidlet(); } if (selectitem == 3) { } } if(c == pubclass.menucommand){ pubclass.return_menumidlet(); } } } //=========================end================================ //=========================addpersonmidlet添加联系人类================================ package messagemidlet; import javax.microedition.lcdui.*; import javax.microedition.rms.*; public class addpersonmidlet extends form implements commandlistener { //构造公共类实例 private pubclass pubclass = new pubclass(); /** constructor */ public addpersonmidlet() { super(''); this.settitle('添加联系人'); for(int i=0;i this.append(pubclass.person[i]); } //构造按钮 pubclass.exitcommand = new command('返回', command.ok, 1); pubclass.okcommand = new command('保存', command.back, 2); //添加监听 this.addcommand(pubclass.exitcommand); this.addcommand(pubclass.okcommand); this.setcommandlistener(this); } //添加记录 private void addrecord(){ recordstore rs =null; rs = pubclass.open(); try { //取得textfield每个直,以数组形式保存 string[] getstring = new string[pubclass.length]; for(int i=0;i //构造personclass实例 personclass personclass = new personclass(); personclass.write(getstring); byte[] data = personclass.changetobytearray(); int recordid = personclass.getrecordid(); if (recordid != -1) { rs.setrecord(recordid, data, 0, data.length); } else { //添加记录 recordid = rs.addrecord(data, 0, data.length); } setget.setdelid(0); mainmidlet mainmidlet = new mainmidlet(); pubclass.alert('添加成功!返回中.......', mainmidlet); } catch (exception e) { pubclass.alert('添加联系人失败'); } } public void commandaction(command c, displayable d) { if(c == pubclass.okcommand){ //判断至少要填写姓名 if(pubclass.person[0].getstring() == null || pubclass.person[0].getstring() == '' ){ pubclass.alert('至少要填写姓名'); }else{ //添加记录 addrecord(); } } if(c == pubclass.exitcommand){ pubclass.return_mainmidlet(); } } } //=========================end================================ //=========================personlistmidlet联系人列表类(显示联系人列表)================================ package messagemidlet; import javax.microedition.lcdui.*; import javax.microedition.rms.*; public class personlistmidlet extends list implements commandlistener { //构造公共类实例 private pubclass pubclass = new pubclass(); private personclass personclass = new personclass(); public int[] recordids; /** constructor */ public personlistmidlet() { super('联系人列表',list.implicit); personlist(); //构造按钮 pubclass.selectcommand = new command('查看', command.screen, 2); pubclass.exitcommand = new command('编辑', command.exit, 1); //添加监听 this.addcommand(pubclass.exitcommand); this.addcommand(pubclass.selectcommand); this.setcommandlistener(this); } //用户列表 public void personlist() { recordstore rs = null; rs = pubclass.open(); try { byte[] data; //建立枚举,取出记录 recordenumeration re = rs.enumeraterecords(null, null, false); //判断是否又记录 if (re.hasnextelement()) { int records=re.numrecords();//取得记录数 recordids=new int[records];//recordid记录数组 for(int i=0;i //保存id data = rs.getrecord(recordids[i]); personclass.changefrombytearray(data); this.append(''+personclass.getperson(0)+'',pubclass.createimage('/images/per.png'));//插入此record名称 } setget.setistrue(true); } else { this.append('还未添加联系人?', null); setget.setistrue(false); } } catch (exception e) { } } //全局变量id private void setgetid() { int itemid = this.getselectedindex(); setget.setid(recordids[itemid]); } //全局变量delid private void setgetdelid() { int itemid = this.getselectedindex(); setget.setdelid(recordids[itemid]); } private void setgetmodid(){ int itemid = this.getselectedindex(); setget.setmodid(recordids[itemid]); } //提示信息并返回 public void alernone(){ mainmidlet mainmidlet = new mainmidlet(); pubclass.alert('无法操作',mainmidlet); } public void commandaction(command c, displayable d) { if(c ==pubclass.exitcommand ){ if (setget.getistrue()){ this.setgetdelid(); this.setgetmodid(); pubclass.return_operatemidlet(); }else{ alernone(); } } if(c ==pubclass.selectcommand ){ if (setget.getistrue()){ this.setgetid(); pubclass.return_persondetailmidlet(); }else{ alernone(); } } } } //=========================end================================ //=========================searchmidlet查找类================================ package messagemidlet; import javax.microedition.midlet.*; import javax.microedition.lcdui.*; import javax.microedition.lcdui.command; import javax.microedition.lcdui.displayable; public class searchmidlet extends textbox implements commandlistener{ //构造公共类实例 private pubclass pubclass = new pubclass(); /** constructor */ public searchmidlet() { super('查找联系人','',256,0); //构造按钮 pubclass.menucommand = new command('查找', command.screen, 1); pubclass.okcommand = new command('主目录', command.back, 1); //添加监听 this.addcommand(pubclass.menucommand); this.addcommand(pubclass.okcommand); this.setcommandlistener(this); } public void commandaction(command c, displayable d) { if(c ==pubclass.okcommand ){ pubclass.return_menumidlet(); } if(c ==pubclass.menucommand){ //设置全局变量 setget.setstr(this.getstring()); pubclass.return_searchoutmidlet(); } } } //=========================end================================ //=========================searchoutmidlet查找结果类================================ package messagemidlet; import javax.microedition.lcdui.*; import javax.microedition.rms.*; import java.io.*; public class searchoutmidlet extends list implements commandlistener { //构造公共类实例 private pubclass pubclass = new pubclass(); private personclass personclass = new personclass(); public int[] recordids; /** constructor */ public searchoutmidlet() { super('查找结果', list.implicit); personlist(); //构造按钮 pubclass.selectcommand = new command('查看', command.screen, 2); pubclass.exitcommand = new command('编辑', command.exit, 1); //添加监听 this.addcommand(pubclass.exitcommand); this.addcommand(pubclass.selectcommand); this.setcommandlistener(this); } //用户列表 public void personlist() { recordstore rs = null; rs = pubclass.open(); try { byte[] data; //匹配 recordfilter rf = new namefilter(); //建立枚举,取出记录 recordenumeration re = rs.enumeraterecords(rf, null, false); //判断是否又记录 if (re.hasnextelement()) { int records=re.numrecords();//取得记录数 recordids=new int[records];//recordid记录数组 for(int i=0;i //保存id data = rs.getrecord(recordids[i]); personclass.changefrombytearray(data); this.append(''+personclass.getperson(0)+'',pubclass.createimage('/images/per.png'));//插入此record名称 } setget.setistrue(true); } else { this.append('对不起,没有查找到', null); setget.setistrue(false); } } catch (exception e) { } } //全局变量id private void setgetid() { int itemid = this.getselectedindex(); setget.setid(recordids[itemid]); } //全局变量modid private void setgetmodid() { int itemid = this.getselectedindex(); setget.setmodid(recordids[itemid]); } //全局变量delid private void setgetdelid() { int itemid = this.getselectedindex(); setget.setdelid(recordids[itemid]); } //提示信息并返回 public void alernone(){ mainmidlet mainmidlet = new mainmidlet(); pubclass.alert('无法操作',mainmidlet); } public void commandaction(command c, displayable d) { if(c ==pubclass.exitcommand ){ if (setget.getistrue()){ this.setgetmodid(); this.setgetdelid(); pubclass.return_operatemidlet(); }else{ alernone(); } } if(c ==pubclass.selectcommand ){ if (setget.getistrue()){ this.setgetid(); pubclass.return_persondetailmidlet(); }else{ alernone(); } } } } class namefilter implements recordfilter{ public boolean matches(byte[] candidate){ datainputstream person = new datainputstream(new bytearrayinputstream(candidate)); string personcname = ''; try{ personcname = person.readutf(); } catch(exception e){ } personclass personclass = new personclass(); if(personcname.equals(setget.getstr())) return true; else return false; } } //=========================end================================ //=========================persondetailmidlet指定联系人详细信息================================ package messagemidlet; import javax.microedition.lcdui.*; import javax.microedition.rms.*; public class persondetailmidlet extends form implements commandlistener { //构造公共类实例 private pubclass pubclass = new pubclass(); /** constructor */ public persondetailmidlet() { super(''); this.constructorlist(); //构造按钮 pubclass.selectcommand = new command('返回', command.screen, 2); pubclass.exitcommand = new command('主目录', command.exit, 1); //添加监听 this.addcommand(pubclass.exitcommand); this.addcommand(pubclass.selectcommand); this.setcommandlistener(this); } //构造list,显示详细信息 private void constructorlist() { try { this.getpersondetail(); } catch (recordstoreexception ex) { } } //绑定对应id数据,并显示 private void getpersondetail() throws recordstoreexception { recordstore rs = null; //打开数据库 rs = pubclass.open(); //建立枚举,取得对应id的详细信息 try { byte[] data; recordenumeration re = rs.enumeraterecords(null, null, false); data = rs.getrecord(setget.getid()); //重新构造,并把byte转换为string类型 personclass personclass = new personclass(); personclass.changefrombytearray(data); //重新设置用户id int recordid = rs.getnextrecordid(); //给对应的属性赋值 for (int i = 0; i < pubclass.persondetail.length; i++) { this.append(pubclass.persondetail[i]); pubclass.persondetail[i].settext(personclass.getperson(i)); } //设置标题为用户名 this.settitle(personclass.getperson(0)); } catch (recordstorenotopenexception ex) { } } public void commandaction(command c, displayable d) { if(c == pubclass.selectcommand){ pubclass.return_personlistmidlet(); } if(c == pubclass.exitcommand){ pubclass.return_menumidlet(); } } } //=========================end================================ //=========================operatemidlet操作联系人类(这里只有删除功能)================================ package messagemidlet; import javax.microedition.midlet.*; import javax.microedition.lcdui.*; import javax.microedition.rms.*; public class operatemidlet extends list implements commandlistener { //构造公共类实例 private pubclass pubclass = new pubclass(); /** constructor */ public operatemidlet() { super('联系人', list.implicit); for (int i = 0; i < pubclass.operatelist.length; i++) { this.append(pubclass.get_operatelist(i), pubclass.createimage('/images/edit.png')); } //构造按钮 pubclass.opercommand = new command('选择', command.screen, 2); pubclass.menucommand = new command('主目录', command.exit, 1); //添加监听 this.addcommand(pubclass.menucommand); this.addcommand(pubclass.opercommand); this.setcommandlistener(this); } //删除指定记录 public void del(int delid) { personclass personclass = new personclass(); recordstore rs = null; rs = pubclass.open(); try { //判断是否又记录 if(rs.getnumrecords()<1){ pubclass.alert('还未添加记录!返回中.......'); }else{ //bug rs.deleterecord(delid); alertinfo('删除成功!返回中.......'); } } catch (exception e) { alertinfo('删除失败!返回中.......'); } } //全部删除记录 public void delall() { personclass personclass = new personclass(); recordstore rs = null; rs = pubclass.open(); //判断是否又记录 try { if (rs.getnumrecords() < 1) { pubclass.alert('还未添加记录!返回中.......'); } else { //构造recordenumeration实例,取出记录 recordenumeration re = rs.enumeraterecords(null, null, false); //根据id,循环删除 while (re.hasnextelement()) { int recoidid = re.nextrecordid(); rs.deleterecord(recoidid); } alertinfo('删除成功!返回中.......'); } } catch (exception e) { alertinfo('删除失败!返回中.......'); } } public void alertinfo(string info){ personlistmidlet personlistmidlet = new personlistmidlet(); pubclass.alert(in, fo,personlistmidlet); } public void commandaction(command c, displayable d) { if(c ==pubclass.menucommand ){ pubclass.return_menumidlet(); } if(c ==pubclass.opercommand ){ int selectitem = this.getselectedindex(); //尽量不使用switch,用if提高速度,虽然麻烦点,经验所得 if (selectitem == 0) { pubclass.return_modifypersonmidlet(); } if (selectitem == 1) { del(setget.getdelid()); setget.setdelid(0); } if (selectitem == 2) { delall(); setget.setdelid(0); } } } } //=========================end================================ //=========================modifypersonmidlet修改指定联系人详细信息================================ package messagemidlet; import javax.microedition.lcdui.*; import javax.microedition.rms.*; public class modifypersonmidlet extends form implements commandlistener { //构造公共类实例 private pubclass pubclass = new pubclass(); /** constructor */ public modifypersonmidlet() { super(''); try { this.getpersondetail(); } catch (recordstoreexception ex) { } //构造按钮 pubclass.exitcommand = new command('主目录', command.ok, 1); pubclass.okcommand = new command('修改', command.back, 2); //添加监听 this.addcommand(pubclass.exitcommand); this.addcommand(pubclass.okcommand); this.setcommandlistener(this); } //绑定对应id数据,并显示 private void getpersondetail() throws recordstoreexception { recordstore rs = null; //打开数据库 rs = pubclass.open(); //建立枚举,取得对应id的详细信息 try { byte[] data; recordenumeration re = rs.enumeraterecords(null, null, false); data = rs.getrecord(setget.getmodid()); //重新构造,并把byte转换为string类型 personclass personclass = new personclass(); personclass.changefrombytearray(data); //重新设置用户id int recordid = rs.getnextrecordid(); //给对应的属性赋值 for (int i = 0; i < pubclass.person.length; i++) { this.append(pubclass.person[i]); pubclass.person[i].setstring(personclass.getperson(i)); } //设置标题为用户名 this.settitle('修改'+personclass.getperson(0)); } catch (recordstorenotopenexception ex) { } rs.closerecordstore(); } //修改联系人 public void updataperson() { recordstore rs = null; rs = pubclass.open(); try { //取得textfield每个直,以数组形式保存 string[] getstring = new string[pubclass.length]; for (int i = 0; i < pubclass.length; i++) { getstring[i] = pubclass.person[i].getstring(); } //构造personclass实例 personclass personclass = new personclass(); personclass.write(getstring); byte[] data = personclass.changetobytearray(); int recordid = personclass.getrecordid(); if (recordid != -1) { rs.setrecord(recordid, data, 0, data.length); } else { //修改记录 rs.setrecord(setget.getmodid(),data,0,data.length);//rs.setrecord(setget.getmodid(), data,0, data.length); personclass.setrecordid(recordid); } setget.setmodid(0); personlistmidlet personlistmidlet = new personlistmidlet(); pubclass.alert('修改成功!返回中.......',personlistmidlet); } catch (exception e) { personlistmidlet personlistmidlet = new personlistmidlet(); pubclass.alert('修改失败',personlistmidlet); } } public void commandaction(command c, displayable d) { if(c == pubclass.exitcommand){ pubclass.return_menumidlet(); } if(c == pubclass.okcommand){ //判断至少要填写姓名 if (pubclass.person[0].getstring() == null || pubclass.person[0].getstring() == '') { pubclass.alert('至少要填写姓名'); } else { this.updataperson(); } } } } //=========================end================================
|
闽公网安备 35060202000074号