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

📄 configform.java

📁 基于J2ME
💻 JAVA
字号:
package com.yxw.view;

import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
import java.io.IOException;

import javax.microedition.lcdui.*;

import com.yxw.util.RMSDao;
import com.yxw.control.*;
public class ConfigForm extends Form implements ItemStateListener,
		CommandListener {

	private ChoiceGroup connectionMethod;
	private ChoiceGroup cacheSize;
	private Command submit;
	private Command cancel;
	private RMSDao rmsDao;
	private boolean isProxy;
	private int size;
	public ConfigForm(String arg0) {
		super(arg0);
		this.connectionMethod=new ChoiceGroup("连接方式",Choice.EXCLUSIVE);
		this.connectionMethod.append("代理", null);
		this.connectionMethod.append("直连", null);
		this.connectionMethod.setSelectedIndex(1, true);
		this.cacheSize=new ChoiceGroup("缓存大小(KB)",Choice.POPUP);
		this.cacheSize.append("100", null);
		this.cacheSize.append("150", null);
		this.cacheSize.append("200", null);
		this.cacheSize.append("250", null);
		this.cacheSize.append("300", null);
		rmsDao=new RMSDao();
		byte[] data=this.rmsDao.getConfig("config");
		if(data==null){
			this.size=200;
			this.isProxy=false;
			this.cacheSize.setSelectedIndex(2, true);
			this.connectionMethod.setSelectedIndex(1, true);
			System.out.println("无配置数据");
		}else{
			ByteArrayInputStream inputStream=new ByteArrayInputStream(data);
			DataInputStream dis=new DataInputStream(inputStream);
			try {
				this.size=dis.readInt();
				this.isProxy=dis.readBoolean();
				inputStream.reset();
				inputStream.close();
				dis.close();
				this.cacheSize.setSelectedIndex((this.size-100)/50, true);
				if(this.isProxy){
					this.connectionMethod.setSelectedIndex(0, true);
				}else{
					this.connectionMethod.setSelectedIndex(1, true);
				}
				
				
			} catch (IOException e) {
				// TODO 自动生成 catch 块
				this.size=200;
				this.isProxy=false;
				this.cacheSize.setSelectedIndex(2, true);
				this.connectionMethod.setSelectedIndex(1, true);
				e.printStackTrace();
			}
			
		}
		this.submit=new Command("确定",Command.ITEM,1);
		this.cancel=new Command("取消",Command.CANCEL,2);
		this.addCommand(this.submit);
		this.addCommand(this.cancel);
		this.append(this.connectionMethod);
		this.append(this.cacheSize);
		//this.append(new StringItem("testItem","fsdf"));
		this.setItemStateListener(this);
		this.setCommandListener(this);
		// TODO 自动生成构造函数存根
	}

	public void itemStateChanged(Item arg0) {
		// TODO 自动生成方法存根

		if(arg0==this.connectionMethod){
			int t=this.connectionMethod.getSelectedIndex();
			StringItem si=new StringItem("连接方式为:",String.valueOf(t));
		   // this.append(si);
		    if(t==1){
		    	this.isProxy=false;
		    }else{
		    	this.isProxy=true;
		    }
		    
		}else if(arg0==this.cacheSize){
			int t=this.cacheSize.getSelectedIndex();
			StringItem si=new StringItem("缓存大小为:",String.valueOf(this.cacheSize.getSelectedIndex()));
		   // this.append(si);
		    this.size=Integer.parseInt(this.cacheSize.getString(t));
		}else{
			System.out.println("StringItem...");
		}
		
	}

	public void commandAction(Command arg0, Displayable arg1) {
		// TODO 自动生成方法存根

		if(arg0==this.submit){
			int t=this.rmsDao.saveOrUpdateConfig("config", this.size, this.isProxy);
			if(t==0){
				
				MainMidlet.replace(new InfoForm("提示信息","配置信息保存失败"));
			}else{
				MainMidlet.replace(new InfoForm("提示信息","配置信息已保存,在下次启动程序时生效"));
			}
			//System.out.println("保存配置信息:"+t);
		}
		else if(arg0==this.cancel){
			MainMidlet.goBack();
		}
	}

}

⌨️ 快捷键说明

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