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

📄 blueclientgui.java

📁 欢迎使用蓝牙联网坦克大战
💻 JAVA
字号:
/* * Bluetooth Multiplayer Games Framework * Author: Francesco Panciroli (email fif0302@iperbole.bologna.it) * Copyright (C) 2006  Francesco Panciroli *  * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of 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 of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. *  * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. */package newpackage;import javax.bluetooth.RemoteDevice;import javax.bluetooth.ServiceRecord;import javax.bluetooth.UUID;import javax.microedition.io.Connection;import javax.microedition.lcdui.Alert;import javax.microedition.lcdui.AlertType;import javax.microedition.lcdui.Command;import javax.microedition.lcdui.CommandListener;import javax.microedition.lcdui.Display;import javax.microedition.lcdui.Displayable;import javax.microedition.lcdui.List;import org.apache.log4j.Category;public class BlueClientGUI extends List implements CommandListener {	static Category log = Category.getInstance("panci.bluemgf.BlueClientGUI");	private BlueMIDlet midlet;	private BlueClientBT blueClientBT;	protected UUID serviceUUID;	private final Command OK_CMD = new Command("Select", Command.SCREEN, 1);	private final Command SEARCH_CMD = new Command("Restart Search", Command.SCREEN, 2);	private final Command BACK_CMD = new Command("Back", Command.BACK, 3);	private final Command LOG_CMD = new Command("Log", Command.SCREEN, 3);	public BlueClientGUI(BlueMIDlet midlet) {		super("Server devices", List.IMPLICIT);    	log.debug("Constructor!");			this.midlet = midlet;		serviceUUID = midlet.getServiceUUID();		blueClientBT = new BlueClientBT(this);		addCommand(OK_CMD);		addCommand(SEARCH_CMD);		addCommand(BACK_CMD);		if (midlet.isLogAvailable())			addCommand(LOG_CMD);		append("[Please Wait...]", null);		setCommandListener(this);	}	/**	 * refresh the list with blutooth devices	 */	public void showui() {		super.deleteAll();		if (blueClientBT.services.size() > 0) {			for (int i = 0; i < blueClientBT.services.size(); i++) {				try {					ServiceRecord record = (ServiceRecord) blueClientBT.services.elementAt(i);					RemoteDevice device = record.getHostDevice();					String name = device.getFriendlyName(false) + "-" + device.getBluetoothAddress();					append(name, null);				} catch (Exception e) {					e.printStackTrace();				}			}		} else {			append("No Server Found!", null);		}	}	public void showWait() {		super.deleteAll();		append("Waiting for game start...", null);		removeCommand(OK_CMD);		removeCommand(SEARCH_CMD);	}	public void serviceSearchCompleted(int returnCode) {		//log.debug("serviceSearchCompleted: returnCode = " + returnCode);		showui();	}	public void connectionOpened(BlueConnection bconn) {		showWait();		Connection conn = bconn.conn;		midlet.handleEvent(BlueEventHandler.EVENT_CLIENT_WAITING_FOR_START, conn);	}	public void commandAction(Command c, Displayable d) {    	//log.debug("Called BlueClientGUI.commandAction with parameters " + c + ", " + d);    	//log.debug("Command description: " + c.getLabel() + " - " + c.getCommandType());		if (c == SEARCH_CMD) {			blueClientBT.services.removeAllElements();			blueClientBT.startInquiry();		} else if (c == BACK_CMD) {			midlet.backToMenu();		} else if (c == LOG_CMD) {			midlet.showLog(this);		} else {			BlueConnection bconn = blueClientBT.getBlueConnectionByListIndex(getSelectedIndex());			if (bconn.conn == null) {				blueClientBT.openConnection(bconn);			} else {				Alert al = new Alert("Warning", "Connection already established!", null, AlertType.WARNING);				al.setTimeout(BlueMIDlet.ALERT_TIMEOUT);				Display.getDisplay(midlet).setCurrent(al, this);			}		}	}	public UUID getServiceUUID() {		return serviceUUID;	}}

⌨️ 快捷键说明

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