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

📄 setting.java

📁 j2me开发 简单示例 包括 游戏主菜单、rms功能模块
💻 JAVA
字号:
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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -