//=====================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用户属性类===========