?? recordidmidlet.java
字號:
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.rms.*;
// A first MIDlet with simple text and a few commands.
public class RecordIDMIDlet extends MIDlet
implements CommandListener {
private Command exitCommand;
//The display for this MIDlet
private Display display;
public RecordIDMIDlet() {
display = Display.getDisplay(this);
exitCommand = new Command("離開", Command.EXIT, 1);
}
// Start the MIDlet by creating the TextBox and
// associating the exit command and listener.
public void startApp() {
TextBox aTextBox = new TextBox("主畫面",null,256,TextField.ANY);
RecordStore rs = null;
byte[] name =null;
boolean existingOrNot = false;
boolean OK = true;
existingOrNot = existing("aRS");
if(existingOrNot){
try{
rs = RecordStore.openRecordStore("aRS",false);
}
catch(Exception e){
OK = false;
}
finally{
if(OK){
aTextBox.setString("aRS已存在并且已打開");
}
else{
aTextBox.setString("aRS已存在但無法打開");
}
}
}
else{
try{
rs = RecordStore.openRecordStore("aRS",true);
}
catch(Exception e){
OK = false;
}
finally{
if(OK){
aTextBox.setString("aRS雖未存在,但已創建并完成打開的操作!");
}
else{
aTextBox.setString("aRS雖未存在,但無法創建,打開文件失敗!");
}
}
}
if(OK){
try{
for(int i=1;i<=3;i++){
name = ("JIDCA"+i).getBytes();
rs.addRecord(name,0,name.length);
}
}
catch(Exception e){
aTextBox.setString("新增記錄的操作失敗!");
}
try{
rs.deleteRecord(1);
aTextBox.setString("recordID為1的記錄已被刪除");
}
catch(InvalidRecordIDException e){
try{
aTextBox.setString("目前共有" + rs.getNumRecords() +
"筆記錄,但找不到recordID為1的記錄");
}
catch(RecordStoreNotOpenException rse){
}
}
catch(RecordStoreException e){ //針對deleteRecord
}
finally{
try{
rs.closeRecordStore();
}
catch(Exception e){
}
}
}
aTextBox.addCommand(exitCommand);
aTextBox.setCommandListener(this);
display.setCurrent(aTextBox);
}
// Pause is a no-op because there are no background
// activities or record stores to be closed.
public void pauseApp() { }
// Destroy must cleanup everything not handled
// by the garbage collector.
// In this case there is nothing to cleanup.
public void destroyApp(boolean unconditional) { }
public boolean existing(String recordStoreName) {
boolean existingOrNot = false;
RecordStore rs = null;
if(recordStoreName.length() > 32) return false;
try{
rs = RecordStore.openRecordStore(recordStoreName,false);
}
catch(RecordStoreNotFoundException e){
existingOrNot = false;
}
catch(Exception e){
}
finally{
try{
rs.closeRecordStore();
}
catch(Exception e){
}
}
return existingOrNot;
}
public void commandAction(Command c, Displayable s) {
destroyApp(false);
notifyDestroyed();
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -