13,100
社区成员
发帖
与我相关
我的任务
分享
public void commandAction(Command cmd,Displayable display)
{
if(cmd==okCommand)
{
if(currentForm.equals("Menu Form List"))
{
javax.microedition.lcdui.List down= (javax.microedition.lcdui.List)display1.getCurrent();
switch(down.getSelectedIndex())
{
case 0:showMessageForm();break;
case 1:showPhoneBookForm();break;
}
}
else if(currentForm.equals("Message"))
{
javax.microedition.lcdui.List down= (javax.microedition.lcdui.List)display1.getCurrent();
switch(down.getSelectedIndex())
{
case 0:showInput();break;
case 1:break;
case 2:break;
}
}
else if(currentForm.equals("Phone Book"))//1号错误: {
javax.microedition.lcdui.List down= (javax.microedition.lcdui.List)display1.getCurrent();
switch(down.getSelectedIndex())
{
case 0:showAddForm();break;
case 1:
int num=rsc. numOfRecord();
for(int i=0;i<num;i++)
{
System.out.println(rsc.getRecordStore(i));
}
break;
case 2:break;
}
}
}
else if(cmd==addCommand)//2号错误:
{
rsc= new RecordStoreCom();
rsc.openStore("PhoneBookStore");
String name=nameTextField.getString();
String mobile=mobileTextField.getString();
String perPhone=perTextField.getString();
String email=emailTextField.getString();
// String date=Calendar.YEAR+":"+Calendar.MONTH+":"+Calendar.DAY_OF_MONTH+":"+Calendar.DATE;
String contactor=name+"/"+mobile+"/"+perPhone+"/"+email;
errorMessageAlert.setString("Input some message into textforms.");
display1.setCurrent(errorMessageAlert);
rsc.addRecordStore(contactor);
System.out.println(rsc.getRecordStore(1));
}
}
public class RecordStoreCom
{
String name;
String message;
String toPhone;
String fromPhone;
String date;
RecordStore recordStore=null;
//获得存储记录的数量
public int numOfRecord()
{
int numRecords=0;
try
{
numRecords=recordStore.getNumRecords();
}
catch(RecordStoreException e)
{
System.out.println("Error in getting the number of recordStore---"+e);
}
return numRecords;
}
//打开存储记录.
public RecordStore openStore(String fileName)
{
try
{
recordStore=RecordStore.openRecordStore(fileName,true);
}
catch(RecordStoreException rse)
{
rse.printStackTrace();
}
return recordStore;
}
//修改存储中的信息并保存。
。。。。。。。。。。。。。
//获得存储的信息的方法
public String getRecordStore(int recordId)
{
Information Info= new Information();
int num=0;
String message=null;
try
{
num=recordStore.getNumRecords();
}
catch(RecordStoreException e)
{
System.out.println("Get recordStore Exception:"+e);
}
byte[] data=null;
if(num>0)
{
try
{
data=recordStore.getRecord(recordId);
Info.decode(data);
message+="Name:"+Info.name;
message+="\n Mobile Phone:"+Info.mobile;
message+="\n Permanent Phone"+Info.perPhone;
message+="\n Email:"+Info.email;
}
catch (InvalidRecordIDException e) { }
catch(RecordStoreException e)
{
System.out.println("GetRecordStore Exception:"+e);
}
}
return message;
}
//对信息进行格式化.
public class Information
{
String name;
String mobile;
String perPhone;
String email;
public void decode(byte[] data)
{
String mess=new String(data);
int pos1=mess.indexOf('/');
if (pos1>=0) {
name = mess.substring(0,pos1);
int pos2 = mess.indexOf('/',pos1+1);
if (pos2>pos1) {
mobile= mess.substring(pos1+1,pos2);
int pos3 = mess.indexOf('/',pos2+1);
if (pos3>pos2) {
perPhone = mess.substring(pos2+1,pos3);
email = mess.substring(pos3+1,mess.length());
}
}
}
}
}
//删除存储中的信息.
。。。。。。。。。。
//添加存储记录的信息
public boolean addRecordStore(String mesContent)
{
byte[] data=mesContent.getBytes();
int id;
int recId=-1;
/*
try
{
id=recordStore.getNextRecordID();
}
catch(RecordStoreException e)
{
System.out.println("RecordStoreException : The RecordStore RecordID is "+recId);
}
*/
try
{
recordStore.addRecord(data,0,data.length);
}
catch(RecordStoreException e)
{
System.out.println("RecordStoreException : The RecordStore RecordID is "+recId);
}
return true;
}
}