⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 scores.java

📁 孤单惊魂
💻 JAVA
字号:
import javax.microedition.lcdui.*;import javax.microedition.rms.*;import javax.microedition.lcdui.Graphics;import javax.microedition.lcdui.game.*;public class Scores    extends GameCanvas implements CommandListener {  private int[] hiScoress = new int[5];  private static Displayable instance;  synchronized public static Displayable getInstance() {    if (instance == null) {      instance = new Scores();    }    return instance;  }  private Scores() {    super(true);    addCommand(new Command("返回", Command.BACK, 1));    setCommandListener(this);    start();  }  public void start() {    readHiScores();    Graphics g = getGraphics();    draw(g);  }  private void readHiScores() {    RecordStore rs = null;    try {      rs = RecordStore.openRecordStore("HiScores", false);    }    catch (Exception e) {    }    if (rs != null) {      try {        int len;        byte[] recordData = new byte[8];        for (int i = 1; i <= rs.getNumRecords(); i++) {          if (rs.getRecordSize(i) > recordData.length) {            recordData = new byte[rs.getRecordSize(i)];          }          len = rs.getRecord(i, recordData, 0);          hiScoress[i - 1] = (Integer.parseInt(new String(recordData, 0, len)));        }      }      catch (Exception e) {        System.err.println("Failed reading hi scores!");      }      try {        rs.closeRecordStore();      }      catch (Exception e) {        System.err.println("Failed closing hi score record store!");      }    }    else {      for (int i = 0; i < 5; i++) {        hiScoress[i] = 0;      }    }  }  private void draw(Graphics g) {    g.setColor(220, 220, 140);    g.fillRect(0, 0, getWidth(), getHeight());    g.setColor(250, 0, 12);    g.setFont(Font.getFont(Font.FACE_SYSTEM, Font.STYLE_BOLD, Font.SIZE_LARGE));    g.drawString("玩家最高记录", getWidth() / 2, 30, Graphics.TOP | Graphics.HCENTER);    for (int i = 0; i < 5; i++) {      g.drawString("第" + Integer.toString(i + 1) + "名 :   " +                   Integer.toString(hiScoress[i]), getWidth() / 2,                   getHeight() / 2 - 30 + (i * 15),                   Graphics.TOP | Graphics.HCENTER);    }  }  public void commandAction(Command c, Displayable s) {    Navigator.flow(c.getLabel());  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -