不一样的手机名片式电话本,其中包括添加新记录

源代码在线查看: findrecord.java

软件大小: 48 K
上传用户: lwp
关键词: 手机 片式 电话 记录
下载地址: 免注册下载 普通下载 VIP

相关代码

				package PhoneBook;
				
				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;
				
				
				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 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());
							RecordEnumeration re=null;
							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");
								}
							}
						}
					}
					
				      
					
				
				}
							

相关资源