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

📄 recordlistenerexample.java

📁 rms常用操作例子,可通过这些例子修改成你想要的代码,绝对有用!
💻 JAVA
字号:
import javax.microedition.midlet.*;
import javax.microedition.rms.*;

public class RecordListenerExample extends MIDlet implements RecordListener{
  RecordStore rs1=null;
  RecordStore rs2=null;
  public RecordListenerExample(){}
  public void startApp()throws MIDletStateChangeException {
    //open two Record Stores
    try {
      rs1 =RecordStore.openRecordStore("test1 ",true);
      rs1.addRecordListener(this);
    }catch(Exception e){}
    try {
      rs2 =RecordStore.openRecordStore("test2 ",true);
    }catch(Exception e){}
    //add two records to rs1
    byte data []=new byte [4 ];
    for(int j=0;j<2;j++){
      try {
        int i=rs1.getNextRecordID();
        data [0 ] = (byte)((i >>24)&0xff);
        data [1 ] = (byte)((i >>16)&0xff);
        data [2 ] = (byte)((i >>8)&0xff);
        data [3 ] = (byte)(i &0xff);
        System.out.println("record #"+rs1.addRecord(data,0,4)+" is added to Record Store 1 ");
      }catch (Exception e){}
    }
    //modified the second last added record
    try {
      int id=rs1.getNextRecordID()-2;
      data=rs1.getRecord(id);
      data [0 ]+=1;
      rs1.setRecord(id,data,0,4);
      System.out.println("record #"+id+" of Record Store 1 is modified..");
    }catch(Exception e){}
    //delete the last added
    try {
      int id=rs1.getNextRecordID()-1;
      rs1.deleteRecord(id);
      System.out.println("record #"+id+" of Record Store 1 is deleted..");
    }catch (Exception e){}
    //end
    destroyApp(true);
    notifyDestroyed();
  }
  public void pauseApp(){}
  public void destroyApp(boolean unconditional){
  
  //close the two Record Stores
  try {
    if(rs1!=null)rs1.closeRecordStore();
  }catch(Exception e){}
  try {
    if(rs2!=null)rs2.closeRecordStore();
  }catch (Exception e){}
}
//implement RecordListener
public void recordAdded(RecordStore rs,int rid){
  if(rs==rs1){
  try {
    byte data []=rs.getRecord(rid);
    int id=rs2.addRecord(data,0,data.length);
    System.out.println("record #"+id+" is added to Record Store 2..");
  }catch(Exception e){}
  }
}
public void recordChanged(RecordStore rs,int rid){
  if(rs==rs1){
    try {
      byte data []=rs.getRecord(rid);
      rs2.setRecord(rid,data,0,data.length);
      System.out.println("record #"+rid+" of Record Store 2 is modified..");
    }catch(Exception e){}
  }
}

public void recordDeleted(RecordStore rs,int rid){
  if(rs==rs1){
    try {
      rs2.deleteRecord(rid);
      System.out.println("record #"+rid+" of Record Store 2 is deleted..");
    }catch(Exception e){}
  }
}
}

⌨️ 快捷键说明

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