📄 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 + -