recordstoreexample.java

来自「j2me实例代码」· Java 代码 · 共 69 行

JAVA
69
字号
package rms;

import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
import javax.microedition.rms.*;
import javax.microedition.lcdui.*;
import java.io.*;

public class RecordStoreExample extends MIDlet implements CommandListener{
	private Display display;
	private Alert alert;
	private Form form;
	private Command exit;
	private Command start;
	private RecordStore recordstore=null;
	public RecordStoreExample() {
		super();
		display=Display.getDisplay(this);
		exit=new Command("Exit",Command.SCREEN,1);
		start=new Command("Start",Command.SCREEN,1);
		form=new Form("Record Store");
		form.addCommand(exit);
		form.addCommand(start);
		form.setCommandListener(this);
	}
	protected void startApp() throws MIDletStateChangeException {
		display.setCurrent(form);
	}
	

	protected void pauseApp() {}

	protected void destroyApp(boolean arg0){}

	public void commandAction(Command c, Displayable d) {
		if(c==exit){
			destroyApp(false);
			notifyDestroyed();
		}
		else if(c==start){
			try{
				recordstore=RecordStore.openRecordStore("myRecordStore",true);
				
			}catch(Exception e){
				alert=new Alert("Creating fail",e.toString(),null,AlertType.WARNING);
				alert.setTimeout(Alert.FOREVER);
				display.setCurrent(alert);
			}
			try{
				recordstore.closeRecordStore();
			}catch(Exception e){
				alert=new Alert("Closing fail",e.toString(),null,AlertType.WARNING);
				alert.setTimeout(Alert.FOREVER);
				display.setCurrent(alert);
				
			}		
			if(RecordStore.listRecordStores()!=null){
				try{
					RecordStore.deleteRecordStore("myRecordStore");
				}catch(Exception e){
					alert=new Alert("Removing fail",e.toString(),null,AlertType.WARNING);
					alert.setTimeout(Alert.FOREVER);
					display.setCurrent(alert);
				}
			}
		}
	}
}

⌨️ 快捷键说明

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