📄 deleterecord.java
字号:
package PhoneBook;
import java.util.Vector;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.MIDlet;
import javax.microedition.rms.*;
public class DeleteRecord extends List implements CommandListener {
private Displayable dis;
private MIDlet mid;
private RecordStore rs=null;
private RecordEnumeration re=null;
private Vector recordIds=null;
private int count=0;
private static final Command deleteCommand=new Command("删除",Command.OK,1);
private static final Command backCommand=new Command("返回",Command.BACK ,2);
public DeleteRecord(Displayable dis,MIDlet mid,RecordStore rs){
super("删除记录",Choice.MULTIPLE);
this .dis=dis;
this.mid=mid;
this.rs=rs;
this.addCommand(backCommand);
this.addCommand(deleteCommand);
this.setCommandListener(this);
recordIds=new Vector();
SortComparator sortCom=new SortComparator();
if(rs!=null){
try{ Image icon=Image.createImage("/txt.png");
re=rs.enumerateRecords(null,sortCom, true);
byte[] rec;
int id;
while(re.hasNextElement()){
count=count+1;
id=re.nextRecordId();
recordIds.addElement(new Integer(id));
rec=rs.getRecord(id);
BookAccount account=BookAccount.deserialize(rec);
int index=this.append(account.getUserName(), icon);
}
}catch (Exception e){
}finally{
if(re!=null)
re.destroy();
}
}
}
public void commandAction (Command c ,Displayable d){
if(c==backCommand){
Display.getDisplay(mid).setCurrent(dis);
}
if (c==deleteCommand){
if(count==0)
return;
boolean[] selectedArray=new boolean[count];
this.getSelectedFlags(selectedArray);
int i=0,j=0;
for(i=0;i<count;i++)
if(selectedArray[i]==true){
if(!recordIds.isEmpty()){
j=((Integer)recordIds.elementAt(i)).intValue();
try{
rs.deleteRecord(j);
Display.getDisplay(mid).setCurrent(dis);
}catch (Exception e){
e.printStackTrace();
}
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -