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

📄 jmirc.java

📁 用java实现的红外线通讯源码
💻 JAVA
字号:
/*Copyright (C) 2004  Juho Vähä-HerttuaThis 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.util.*;import javax.microedition.midlet.*;import javax.microedition.lcdui.*;public class jmIrc extends MIDlet implements CommandListener {	public final static String VERSION = "0.83";	private final static int FORM_MAIN = 0;	private final static int FORM_CONFIG = 1;	private final static int FORM_ADVANCED = 2;	private final static int FORM_HTTP = 3;	private Display display;	protected static Form mainform;	private int currentform;	private boolean running;	// these are initialized on connection time	private static IrcConnection irc;	private static Listener listener; // irc listener	private static UIHandler uihandler;	private static Database db;	private Command cmd_connect, cmd_config, cmd_advanced, cmd_http, cmd_exit;	private Command cmd_ok, cmd_cancel;	private TextField tf_nick, tf_altnick, tf_host, tf_port, tf_channels, tf_realname;	private TextField tf_hilight, tf_script, tf_passwd, tf_buflines;	private TextField tf_gwhost, tf_gwport, tf_gwpasswd, tf_polltime;	private ChoiceGroup cg_header;	private ChoiceGroup cg_timestamp;	private ChoiceGroup cg_usehttp;	public jmIrc() {		display = Display.getDisplay(this);		cmd_connect = new Command("Connect", Command.OK, 1);		cmd_config = new Command("Configuration", Command.SCREEN,2);		cmd_advanced = new Command("Advanced", Command.SCREEN,3);		cmd_http = new Command("HTTP Config", Command.SCREEN,4);		cmd_exit = new Command("Exit", Command.EXIT, 6);		cmd_ok = new Command("Save", Command.OK, 1);		cmd_cancel = new Command("Cancel", Command.EXIT, 1);		mainform = new Form("jmIrc");		mainform.append("jmIrc " + VERSION + "\n");		mainform.append("By juhovh");		mainform.addCommand(cmd_connect);		mainform.addCommand(cmd_config);		mainform.addCommand(cmd_advanced);		mainform.addCommand(cmd_http);		mainform.addCommand(cmd_exit);		mainform.setCommandListener(this);		db = new Database();		running = false;	}	public void startApp() {		if (!running) {			db.load();			display.setCurrent(mainform);			currentform = FORM_MAIN;			running = true;		}	}	public void commandAction(Command cmd, Displayable disp) {		if (cmd == cmd_connect) {			if (db.usehttp)				irc = (IrcConnection) new HttpIrc(db.gwhost, db.gwport, db.gwpasswd, db.encoding);			else				irc = (IrcConnection) new SocketIrc(db.usepoll, db.encoding);			uihandler = new UIHandler(db, display);			uihandler.setDisplay(uihandler.getConsole());			listener = new Listener(db, irc, uihandler);			listener.start();		}		else if (cmd == cmd_exit) {			try {				destroyApp(true);			} catch (MIDletStateChangeException msce) { ; } // this never happens			notifyDestroyed();		}		else if ((cmd == cmd_ok || cmd == cmd_cancel) && currentform != FORM_MAIN) {			if (currentform == FORM_CONFIG) {				if (cmd == cmd_ok) {					if (tf_nick.getString().equals("")) {						Alert a = new Alert("Warning", "Nick must be set", null, AlertType.WARNING);						a.setTimeout(a.FOREVER);						display.setCurrent(a);						return;					}					currentform = FORM_MAIN;					db.nick = tf_nick.getString();					db.altnick = tf_altnick.getString();					db.host = tf_host.getString();					db.port = Integer.parseInt(tf_port.getString());					db.channels = tf_channels.getString();					db.realname = tf_realname.getString();					db.save_config();				}				currentform = FORM_MAIN;				tf_nick = null;				tf_altnick = null;				tf_host = null;				tf_port = null;				tf_channels = null;				tf_realname = null;				display.setCurrent(mainform);			}			else if (currentform == FORM_ADVANCED) {				currentform = FORM_MAIN;				if (cmd == cmd_ok) {					db.header = cg_header.isSelected(0);					db.timestamp = cg_timestamp.isSelected(0);					db.buflines = Integer.parseInt(tf_buflines.getString());					db.hilight = tf_hilight.getString();					db.startupScript = tf_script.getString();					db.passwd = tf_passwd.getString();					db.save_advanced();				}				cg_header = null;				cg_timestamp = null;				tf_buflines = null;				tf_hilight = null;				tf_script = null;				tf_passwd = null;				display.setCurrent(mainform);			}			else if (currentform == FORM_HTTP) {				currentform = FORM_MAIN;				if (cmd == cmd_ok) {					db.usehttp = cg_usehttp.isSelected(0);					db.gwhost = tf_gwhost.getString();					db.gwport = Integer.parseInt(tf_gwport.getString());					db.gwpasswd = tf_gwpasswd.getString();					db.polltime = Integer.parseInt(tf_polltime.getString());					db.save_http();				}				cg_usehttp = null;				tf_gwhost = null;				tf_gwport = null;				tf_gwpasswd = null;				tf_polltime = null;				display.setCurrent(mainform);			}		}		else {			Form cfgform;			if (cmd == cmd_config) {				tf_nick = new TextField("Nick", db.nick, 20, TextField.ANY);				tf_altnick = new TextField("Alternative nick", db.altnick, 20, TextField.ANY);				tf_host = new TextField("Irc server", db.host, 200, TextField.ANY);				tf_port = new TextField("Irc server port", new Integer(db.port).toString(), 5, TextField.NUMERIC);				tf_channels = new TextField("Channels", db.channels, 600, TextField.ANY);				tf_realname = new TextField("Real name", db.realname, 50, TextField.ANY);				cfgform = new Form("Config");				cfgform.append(tf_nick);				cfgform.append(tf_altnick);				cfgform.append(tf_host);				cfgform.append(tf_port);				cfgform.append(tf_channels);				cfgform.append(tf_realname);				currentform = FORM_CONFIG;			}			else if (cmd == cmd_advanced) {				cg_header = new ChoiceGroup("Header", ChoiceGroup.MULTIPLE);				cg_header.append("Use status header", null);				cg_header.setSelectedIndex(0, db.header);				cg_timestamp = new ChoiceGroup("Timestamp", ChoiceGroup.MULTIPLE);				cg_timestamp.append("Use timestamp", null);				cg_timestamp.setSelectedIndex(0, db.timestamp);				tf_buflines = new TextField("Backbuffer lines", new Integer(db.buflines).toString(), 3, TextField.NUMERIC);				tf_hilight = new TextField("Highlight string", db.hilight, 15, TextField.ANY);				tf_script = new TextField("Startup script (server commands separated with ';')", db.startupScript, 1000, TextField.ANY);				tf_passwd = new TextField("Server password", db.passwd, 10, TextField.PASSWORD);				cfgform = new Form("Advanced Config");				cfgform.append(cg_header);				cfgform.append(cg_timestamp);				cfgform.append(tf_buflines);				cfgform.append(tf_hilight);				cfgform.append(tf_script);				cfgform.append(tf_passwd);				currentform = FORM_ADVANCED;			}			else if (cmd == cmd_http) {								cg_usehttp = new ChoiceGroup("HTTP", ChoiceGroup.MULTIPLE);				cg_usehttp.append("Use HTTP proxy server", null);				cg_usehttp.setSelectedIndex(0, db.usehttp);				tf_gwhost = new TextField("Proxy server", db.gwhost, 200, TextField.ANY);				tf_gwport = new TextField("Proxy port", new Integer(db.gwport).toString(), 5, TextField.NUMERIC);				tf_gwpasswd = new TextField("Proxy password", db.gwpasswd, 10, TextField.PASSWORD);				tf_polltime = new TextField("HTTP poll time (sec):", new Integer(db.polltime).toString(), 2, TextField.NUMERIC);				cfgform = new Form("HTTP Config");				cfgform.append(cg_usehttp);				cfgform.append(tf_gwhost);				cfgform.append(tf_gwport);				cfgform.append(tf_gwpasswd);				cfgform.append(tf_polltime);				currentform = FORM_HTTP;			}			else return;			cfgform.addCommand(cmd_ok);			cfgform.addCommand(cmd_cancel);			cfgform.setCommandListener(this);			display.setCurrent(cfgform);		}	}	/**	 * Time to pause, free any space we don't need right now.	 */	public void pauseApp() {	}	/**	 * Destroy must cleanup everything.	 */	public void destroyApp(boolean unconditional) throws MIDletStateChangeException {		if (irc != null && irc.isConnected()) {			if (!unconditional)				throw new MIDletStateChangeException("IRC is still connected");			this.disconnect();		}		if (uihandler != null) uihandler.cleanup();	}		// Static functions called from other classes	public static void writeLine(String message) {		String ret;		ret = irc.writeData(message + "\r\n");		if (ret != null) {			uihandler.getConsole().writeInfo(ret);		}		listener.setNeedUpdate(true);	}	public static void forceUpdate() {		listener.setNeedUpdate(true);	}	public static void disconnect() {		irc.disconnect();		listener.setNeedUpdate(true);	}	public static int getBytesIn() {		return irc.getBytesIn();	}	public static int getBytesOut() {		return irc.getBytesOut();	}}

⌨️ 快捷键说明

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