📄 recordinfoform.java
字号:
package ch12;
import javax.microedition.lcdui.*;
public class RecordInfoForm
extends Form
implements CommandListener {
//声明一个Display对象
private Display display;
//声明一个Displayable对象承载父窗体
private Displayable parent;
//声明一个返回上一级窗体按钮Command对象
private Command backCommand;
//声明一个构成菜单项的删除按钮Command对象
private Command deleteCommand;
//声明一个构成菜单项的修改按钮Command对象
private Command modifyCommand;
//声明一个代表记录中ID号的StringItem
private StringItem idItem;
//声明一个代表记录中姓名的StringItem
private StringItem nameItem;
//声明一个代表记录中积分的StringItem
private StringItem scoreItem;
//声明一个代表记录中排名的StringItem
private StringItem rankItem;
//声明一个代表记录中日期的StringItem
private StringItem dateItem;
//声明一个自定义的记录存储类对象
private RecordDB rdb;
//声明一个代表ID号的字符串
private String stringID;
//声明一个代表ID号的整型值
private int id;
//声明一个自定义的记录对象
private Record record;
//声明一个代表记录中ID号临时变量
private int _id;
//声明一个代表记录中姓名的临时变量
private String _name;
//声明一个代表记录中积分的临时变量
private String _score;
//声明一个代表记录中排名的临时变量
private String _rank;
//声明一个代表记录中日期的临时变量
private String _date;
/*
1.构造器
*/
public RecordInfoForm(Display d, Displayable p, String idAndName) {
super("记录详细信息");
display = d;
parent = p;
backCommand = new Command("返回", Command.BACK, 1);
deleteCommand = new Command("删除", Command.SCREEN, 2);
modifyCommand = new Command("修改", Command.SCREEN, 2);
addCommand(backCommand);
addCommand(deleteCommand);
addCommand(modifyCommand);
setCommandListener(this);
rdb = new RecordDB();
//从idAndName中取出id
stringID = idAndName.substring(0, 2);
id = Integer.parseInt(stringID);
record = rdb.getRecord(id);
_id = record.getID();
_name = record.getName();
_score = record.getScore();
_rank = record.getRank();
_date = record.getDate();
//注意StringItem和String的区别:前者可以建立一个具有label标签、内容的。后者没有标签,只有内容
idItem = new StringItem("ID:", _id + "");
nameItem = new StringItem("姓名:", _name);
scoreItem = new StringItem("积分:", _score);
rankItem = new StringItem("名次:", _rank);
dateItem = new StringItem("日期:", _date);
append(idItem);
append(nameItem);
append(scoreItem);
append(rankItem);
append(dateItem);
}
/*
2.响应按钮事件
*/
public void commandAction(Command c, Displayable s) {
if (c == backCommand) {
display.setCurrent(parent);
}
else if (c == deleteCommand) {
DeleteRecordForm dff = new DeleteRecordForm(display, parent, _id, _name,
_score, _rank, _date);
display.setCurrent(dff);
}
else if (c == modifyCommand) {
ModifyRecordForm mff = new ModifyRecordForm(display, parent, _id, _name,
_score, _rank, _date);
display.setCurrent(mff);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -