📄 phonelist.java
字号:
/**源代码由程序员联合开发网(www.pudn.com)会员"周润发"收集、整理、重新编辑
*Email: ql_chuanzhang@tom.com
*QQ号:1103798882
*欢迎大家与我联系互相交流学习
**/
package rms_cn;
import java.util.Vector;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.List;
import javax.microedition.rms.RecordStoreNotOpenException;
public class PhoneList extends List implements CommandListener{
private Command cmdBack = new Command("返回",Command.BACK,1);
private Command cmdAdd = new Command("添加电话",Command.SCREEN,1);
private Command cmdDel = new Command("删除电话",Command.SCREEN,1);
private PhoneMIDlet pm;
public PhoneList(PhoneMIDlet pm){
super("电话本",List.IMPLICIT);
this.pm = pm;
this.addCommand(cmdBack);
this.addCommand(cmdAdd);
this.addCommand(cmdDel);
this.setCommandListener(this);
}
public void commandAction(Command c,Displayable d){
if(c==cmdBack){//返回欢迎界面
this.deleteAll();
pm.changeInterface("Welcomecanvas");
}
else if(c==cmdAdd){
pm.changeInterface("AddForm");
}
else if (c==cmdDel){
//删除记录...
this.delete();
this.deleteAll();
pm.changeInterface("PhoneList");//更新
}
}
/*载入所有电话*/
public void loadPhones(){
RMSOpe rmsope = new RMSOpe("PhoneStore");
rmsope.openRecordStore();
Vector v = null;
try {
v = rmsope.getAllPhone();
} catch (RecordStoreNotOpenException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
for(int i=0;i<v.size();i++){
this.append((String)v.elementAt(i), null);
}
rmsope.closeRecordStore();
}
/*删除电话*/
public void delete(){
RMSOpe rmsope = new RMSOpe("PhoneStore");
rmsope.openRecordStore();
rmsope.deletePhone(this.getString(this.getSelectedIndex()));
rmsope.closeRecordStore();
}
/*删除所有电话*/
public void deleteAll(){
int Phone_cnt = this.size();
try{
for(int i=0;i<=Phone_cnt;i++){
this.delete(this.getSelectedIndex());
}
}catch(Exception ex){
ex.printStackTrace();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -