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

📄 listrecord_midlet.java

📁 本光盘是《J2ME无线移动游戏开发》一书的配套光盘
💻 JAVA
字号:
package ch12;

import javax.microedition.midlet.*;
import javax.microedition.rms.*;

public class ListRecord_MIDlet
    extends MIDlet {

  private RecordStore rs = null;
  private RecordEnumeration re = null;
  public ListRecord_MIDlet() {
    try {
      rs.deleteRecordStore("test");
      rs = RecordStore.openRecordStore("test", true);
      byte[] data = "Here is the firstrecord".getBytes();
      rs.addRecord(data, 0, data.length);
      data = "Here is the secondlyrecord".getBytes();
      rs.addRecord(data, 0, data.length);
      data = "Here is the thirdrecord".getBytes();
      rs.addRecord(data, 0, data.length);
      data = "Here is the fourthrecord".getBytes();
      rs.addRecord(data, 0, data.length);
      data = "Here is the fifthrecord".getBytes();
      rs.addRecord(data, 0, data.length);
      data = "Here is the sixthrecord".getBytes();
      rs.addRecord(data, 0, data.length);
      data = "Here is the seventhrecord".getBytes();
      rs.addRecord(data, 0, data.length);
      data = "Here is the eighthrecord".getBytes();
      rs.addRecord(data, 0, data.length);
      System.out.println("记录集中共有:" + rs.getNumRecords() + "条记录");
      re = rs.enumerateRecords(null, null, true);
      System.out.println("枚举集中共有:" + re.numRecords() + "条记录");
      rs.deleteRecord(2);
      System.out.println("枚举集中共有:" + re.numRecords() + "条记录");
      System.out.println("记录ID号为偶数的记录如下:");
      for (int i = 1; i <= re.numRecords();
           i++) {
        try {
          int j = re.nextRecordId();
          if (j % 2 == 0) {
            data = rs.getRecord(j);
            System.out.println("记录ID号为" + j + "的记录:" + new String(data));
          }
        }
        catch (Exception e) {
          System.out.println(e.getMessage());
        }
      }
      System.out.println("记录ID号为奇数的记录如下:");
      re.reset();
      while (re.hasNextElement()) {
        try {
          int j = re.nextRecordId();
          if (j % 2 == 1) {
            data = rs.getRecord(j);
            System.out.println("记录ID号为" + j + "的记录:" + new String(data));
          }
        }
        catch (Exception e) {
          System.out.println(e.getMessage());
        }
      }
    }
    catch (RecordStoreNotOpenException rsnoe) {
      System.out.println(rsnoe.getMessage());
    }
    catch (InvalidRecordIDException iride) {
      System.out.println(iride.getMessage());
    }
    catch (RecordStoreException rse) {
      System.out.println(rse.getMessage());
    }

  }

  public void startApp() {

  }

  public void pauseApp() {
  }

  public void destroyApp(boolean unconditional) {
    try {
      if (rs != null) {
        rs.closeRecordStore();
      }
    }
    catch (RecordStoreException rse) {
      System.out.println(rse.getMessage());
    }
  }
}

⌨️ 快捷键说明

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