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

📄 optionsrs.java

📁 StarShip Battle 2004 game The Developing Mobile Phone Applications With J2ME Technology course provi
💻 JAVA
字号:
import javax.microedition.rms.*;
import java.io.*;

public class OptionsRS {

	private String storeName = "StarShipOptions";
	
	private RecordStore optionStore;
	
	private byte[] currentOption;

    public OptionsRS() {
    	try{
    		optionStore = RecordStore.openRecordStore(storeName,true);
    	}
    	catch(Exception ioe){
    		System.out.println("ERR: Opening RecordStore");
    	}
    }
    
    public byte[] readOption(){
    	try{
    		if(currentOption == null){
    			currentOption = optionStore.getRecord(1);
    		}
    	}catch(Exception e){
    			System.out.println("ERR: Reading Options");
    	}
    	
    	return currentOption;
    }
    
    public void writeOption(byte[] option){
    	try{
    		if(recordExists()){
    			optionStore.setRecord(1,option,0,option.length);
    		}else {
    			optionStore.addRecord(option,0,option.length);
    		}
    	}catch(Exception e){
    		System.out.println("ERR: Saving Options");
    	}
    	
    	currentOption = option;
    }
    
    public boolean recordExists() {
		boolean response = false;
		
		try{
			if(optionStore.getNumRecords() != 1) {
				return false;
			}
		}catch(RecordStoreException rse){
			System.out.println("ERR:OPTIONS: Unable to read the number of records");
			response = false;
		}
		return response; 
    }
    
    public void close(){
    	try{
    		optionStore.closeRecordStore();
    	}catch(Exception e){
    		System.out.println("ERR: Closing RecordStore");
    	}
    }
    
    
}

⌨️ 快捷键说明

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