📄 topscore.java
字号:
import javax.microedition.lcdui.*;
import javax.microedition.rms.*;
public class TopScore
extends Form
implements CommandListener {
Command cmdOK;
Display display;
static private RecordStore rsTop = null; //作保存游戏最高分用
public TopScore(Display display) {
super("Help");
this.display = display;
cmdOK = new Command("OK", Command.OK, 1);
this.addCommand(cmdOK);
openRSTopAnyway("TopScore");
getTop();
StringItem si = new StringItem(" ", "您最富有的时候曾经有 :" + Base.topScore);
this.append(si);
setCommandListener(this);
}
public void commandAction(Command command, Displayable displayable) {
if (Command.OK == command.getCommandType()) {
display.setCurrent(new MenuListCanvas(display));
}
}
static public RecordStore openRSTopAnyway(String rsname) {
//数据仓库的名称大于32个字符就不能够接受
if (rsname.length() > 32) {
return null;
}
try {
rsTop = RecordStore.openRecordStore(rsname, true);
}
catch (Exception e) {
//return null;
System.out.println("openrsTopFalse " + e);
}
return rsTop;
}
//存储最高分
static public void saveTop() {
try{
if (rsTop.getNumRecords() == 0) {
rsTop.addRecord(RecStore.createByteGroup(Base.topScore), 0,
RecStore.createByteGroup(Base.topScore).length);
}
else if (rsTop.getNumRecords() > 0) {
rsTop.setRecord(1, RecStore.createByteGroup(Base.topScore), 0,
RecStore.createByteGroup(Base.topScore).length);
}
rsTop.closeRecordStore();
}catch(Exception e) {}
}
//取出最高分
static public void getTop() {
try{
Base.topScore = RecStore.byte2Long(rsTop.getRecord(1));
rsTop.closeRecordStore();
}catch(Exception e){}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -