📄 midlet4.java
字号:
package prj16_1;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
import javax.microedition.rms.RecordComparator;
import javax.microedition.rms.RecordEnumeration;
import javax.microedition.rms.RecordFilter;
import javax.microedition.rms.RecordStore;
public class MIDlet4 extends MIDlet implements RecordFilter,RecordComparator{
protected void startApp() throws MIDletStateChangeException {
RecordStore rs = null;
try{
rs = RecordStore.openRecordStore("RS1", true);
System.out.println(rs.getSizeAvailable());//记录集可用空间
rs.addRecord("567".getBytes(), 0, "567".getBytes().length);
rs.addRecord("125".getBytes(), 0, "125".getBytes().length);
rs.addRecord("342".getBytes(), 0, "342".getBytes().length);
rs.addRecord("78".getBytes(), 0, "78".getBytes().length);
rs.addRecord("92".getBytes(), 0, "92".getBytes().length);
RecordEnumeration re = rs.enumerateRecords(this, this, false);
while(re.hasNextElement()){
System.out.println(new String(re.nextRecord()));
}
}catch(Exception ex){
ex.printStackTrace();
}
finally{
try{
rs.closeRecordStore();
}catch(Exception ex){}
}
}
public int compare(byte[] rec1,byte[] rec2){
String str1 = new String(rec1);
String str2 = new String(rec2);
int num1 = Integer.parseInt(str1);
int num2 = Integer.parseInt(str2);
if(num1>num2){
return RecordComparator.FOLLOWS;
}
else if(num1<num2){
return RecordComparator.PRECEDES;
}
return RecordComparator.EQUIVALENT;
}
public boolean matches(byte[] candidate){
String str = new String(candidate);
int num = Integer.parseInt(str);
if(num > 100){
return true;
}
return false;
}
protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
// TODO Auto-generated method stub
}
protected void pauseApp() {
// TODO Auto-generated method stub
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -