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

📄 editdetailinfo.java

📁 不一样的手机名片式电话本,其中包括添加新记录
💻 JAVA
字号:
package PhoneBook;

import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
import javax.microedition.rms.*;
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);
				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();
					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 + -