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

📄 findrecord.java

📁 不一样的手机名片式电话本,其中包括添加新记录
💻 JAVA
字号:
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");
				}
			}
		}
	}
	
      
	

}

⌨️ 快捷键说明

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