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

📄 database.java

📁 用java实现的红外线通讯源码
💻 JAVA
字号:
/*Copyright (C) 2003  Sverre Kristian ValskråThis program is free software; you can redistribute it and/ormodify it under the terms of the GNU General Public Licenseas published by the Free Software Foundation; either version 2of the License, or (at your option) any later version.This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See theGNU General Public License for more details.You should have received a copy of the GNU General Public Licensealong with this program; if not, write to the Free SoftwareFoundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.*/package jmirc;import java.io.*;import java.util.*;import javax.microedition.midlet.*;import javax.microedition.lcdui.*;import javax.microedition.io.*;import javax.microedition.rms.*;public class Database {	String nick = "";	String altnick = "";	String host =  "irc.us.ircnet.net";	int port = 6667;	String channels = "#jmIrc";	String realname = "jmIrc user";	String passwd = "";	boolean header=true;	boolean timestamp=false;	String startupScript = "";	String encoding = "ISO-8859-1";	String hilight = "";	int buflines = 50;	boolean usepoll=false;	boolean usehttp=false;	String gwhost =  "";	int gwport = 8080;	String gwpasswd =  "";	int polltime = 10;	private final static int NUMREC = 19;	private final static String NAMEOFSTORE = "jmirccfg";			public Database() {	}	/**	 * returns 	 */	public void load() {		try {			RecordStore rs = RecordStore.openRecordStore(NAMEOFSTORE, true);			int size = rs.getNumRecords();			if (size > 0 && size != NUMREC) {				rs.closeRecordStore();				RecordStore.deleteRecordStore(NAMEOFSTORE);				rs = RecordStore.openRecordStore(NAMEOFSTORE, true);			}			if (size != NUMREC) {				addRecord(rs, nick);				addRecord(rs, altnick);				addRecord(rs, host);				addRecord(rs, new Integer(port).toString());				addRecord(rs, channels);				addRecord(rs, realname);				addRecord(rs, header?"1":"0");				addRecord(rs, timestamp?"1":"0");				addRecord(rs, usepoll?"1":"0");				addRecord(rs, encoding);				addRecord(rs, new Integer(buflines).toString());				addRecord(rs, hilight);				addRecord(rs, startupScript);				addRecord(rs, passwd);				addRecord(rs, usehttp?"1":"0");				addRecord(rs, gwhost);				addRecord(rs, new Integer(gwport).toString());				addRecord(rs, gwpasswd);				addRecord(rs, new Integer(polltime).toString());			}			else {				nick = getRecordString(rs, 1);				altnick = getRecordString(rs, 2);				host = getRecordString(rs, 3);				port = getRecordInt(rs, 4);				channels = getRecordString(rs, 5);				realname = getRecordString(rs, 6);				header = getRecordBoolean(rs, 7);				timestamp = getRecordBoolean(rs, 8);				usepoll = getRecordBoolean(rs, 9);				encoding = getRecordString(rs, 10);				buflines = getRecordInt(rs, 11);				hilight = getRecordString(rs, 12);				startupScript = getRecordString(rs, 13);				passwd = getRecordString(rs, 14);				usehttp = getRecordBoolean(rs, 15);				gwhost = getRecordString(rs, 16);				gwport = getRecordInt(rs, 17);				gwpasswd = getRecordString(rs, 18);				polltime = getRecordInt(rs, 19);			}			rs.closeRecordStore();		}		catch(Exception e) {			e.printStackTrace();			//Debug.writeError(e,display,jmIrc.mainForm);		}	}		private String getRecordString(RecordStore rs,int nr) throws Exception {		byte[] b = rs.getRecord(nr);		return (b != null) ? new String(b) : "";	}	private boolean getRecordBoolean(RecordStore rs,int nr) throws Exception {		byte[] b  = rs.getRecord(nr);		return (b != null && new String(b).equals("1"));	}	private int getRecordInt(RecordStore rs,int nr) throws Exception {		byte[] b = rs.getRecord(nr);		return (b != null) ? Integer.parseInt(new String(b)) : 0;	}		private void addRecord(RecordStore rs,String s) throws Exception {		if (s == null) s = "";		rs.addRecord(s.getBytes(),0,s.length());	}		private void setRecord(RecordStore rs,int nr,String s) throws Exception {		if (s == null) s = "";		rs.setRecord(nr,s.getBytes(),0,s.length());	}	public String[] getChannels() {		return Utils.hasNoValue(channels) ? null :Utils.splitString(channels,",");	}		public void save_config() {		try{			RecordStore rs = RecordStore.openRecordStore(NAMEOFSTORE, true);			setRecord(rs, 1, nick);			setRecord(rs, 2, altnick);			setRecord(rs, 3, host);			setRecord(rs, 4, new Integer(port).toString());			setRecord(rs, 5, channels);			setRecord(rs, 6, realname);			rs.closeRecordStore();		}		catch(Exception e) {			e.printStackTrace();			// error in saving settings, should handle this		}	}	public void save_advanced() {		try {			RecordStore rs = RecordStore.openRecordStore(NAMEOFSTORE, true);			setRecord(rs, 7, header?"1":"0");			setRecord(rs, 8, timestamp?"1":"0");			setRecord(rs, 9, usepoll?"1":"0");			setRecord(rs, 10, encoding);			setRecord(rs, 11, new Integer(buflines).toString());			setRecord(rs, 12, hilight);			setRecord(rs, 13, startupScript);			setRecord(rs, 14, passwd);			rs.closeRecordStore();		}		catch(Exception e) {			e.printStackTrace();			// error in saving settings, should handle this		}	}	public void save_http() {		try {			RecordStore rs = RecordStore.openRecordStore(NAMEOFSTORE, true);			setRecord(rs, 15, usehttp?"1":"0");			setRecord(rs, 16, gwhost);			setRecord(rs, 17, new Integer(gwport).toString());			setRecord(rs, 18, gwpasswd);			setRecord(rs, 19, new Integer(polltime).toString());			rs.closeRecordStore();		}		catch(Exception e) {			e.printStackTrace();			// error in saving settings, should handle this		}	}}

⌨️ 快捷键说明

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