setting.java

来自「j2me开发 简单示例 包括 游戏主菜单、rms功能模块」· Java 代码 · 共 81 行

JAVA
81
字号
package com.gowin.firstgame;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;

public class Setting extends BaseRms {

	private int difficulty ;
	private int autoFire ;
	
	Setting(String rmsName) {
		super(rmsName);
	}

	public int getDifficulty() {
		return difficulty;
	}

	public int getAutoFire() {
		return autoFire;
	}

	public void  loadSetting(){
		open();
		if( getRecordStore() != null){
			close();
		}
	}
	
	
	public void updateSetting(int difficulty, int autoFire){
	
		open();
		this.difficulty = difficulty;
		this.autoFire = autoFire;
		try {
			updateData();
		} catch (Exception e) {
			e.printStackTrace();
		}
		if( getRecordStore() != null){
			close();
		}				
	}

	void createDefaultData() throws Exception {
			ByteArrayOutputStream bStream = new ByteArrayOutputStream(12);
			DataOutputStream oStream = new DataOutputStream(bStream);
			oStream.writeInt( difficulty );
			oStream.writeInt( autoFire );
			oStream.flush();
			oStream.close();
			byte[] record = bStream.toByteArray();
			getRecordStore().addRecord(record, 0, record.length);
		
	}

	
	
	void loadData() throws Exception {		
		byte[] record = getRecordStore().getRecord(1);
		DataInputStream iStream = new DataInputStream( 
				new ByteArrayInputStream(record, 0 , record.length));
		difficulty = iStream.readInt();
		autoFire = iStream.readInt();		
	}

	void updateData() throws Exception {
			ByteArrayOutputStream bStream = new ByteArrayOutputStream(12);
			DataOutputStream oStream = new DataOutputStream(bStream);
			oStream.writeInt( difficulty );
			oStream.writeInt( autoFire );
			oStream.close();
			byte[] record = bStream.toByteArray();
			getRecordStore().setRecord(1 , record, 0, record.length);
	}

}

⌨️ 快捷键说明

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