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

📄 blueservergui.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 java.util.Vector;

import javax.bluetooth.RemoteDevice;
import javax.bluetooth.UUID;
import javax.microedition.io.Connection;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.List;

import org.apache.log4j.Category;

class BlueServerGUI extends List implements CommandListener {

	static Category log = Category.getInstance("panci.bluemgf.BlueServerGUI");

	private BlueMIDlet midlet;

	private BlueServerBT blueServerBT;

    protected UUID serviceUUID;

	private final Command OK_CMD = new Command("Start", Command.OK, 1);

	private final Command BACK_CMD = new Command("Back", Command.BACK, 3);

	private final Command LOG_CMD = new Command("Log", Command.SCREEN, 2);

	private String defaultMessage = "Waiting for clients...";

	public BlueServerGUI(BlueMIDlet midlet) {
		super("Client devices", List.IMPLICIT);
    	log.debug("Constructor!");	

		this.midlet = midlet;
		serviceUUID = midlet.getServiceUUID();

		blueServerBT = new BlueServerBT(this, midlet.getConnectionProtocol());
		
		addCommand(OK_CMD);
		addCommand(BACK_CMD);
		if (midlet.isLogAvailable())
			addCommand(LOG_CMD);

		setCommandListener(this);

		showui();
	}

	/**
	 * refresh the list with blutooth devices
	 */
	public void showui() {
		super.deleteAll();

		if (blueServerBT.connections.size() > 0) {
			for (int i = 0; i < blueServerBT.connections.size(); i++) {
				try {
					Connection conn = (Connection) blueServerBT.connections.elementAt(i);
					RemoteDevice device = RemoteDevice.getRemoteDevice(conn);
					String name = device.getFriendlyName(false) + "-" + device.getBluetoothAddress();
					append(name, null);

				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		} else {
			append(defaultMessage, null);
		}
	}

	public void commandAction(Command c, Displayable d) {
		if (c == BACK_CMD) {
			midlet.backToMenu();
		} else if (c == LOG_CMD) {
			midlet.showLog(this);
		} else {
			// If the number of players is two, create a new vector with the selected connection,
			// otherwise use the vector with all the connections
			if (midlet.getNumberOfPlayers() == 2) {
				Vector conns = new Vector();
				conns.addElement(blueServerBT.connections.elementAt(getSelectedIndex()));
				midlet.handleEvent(BlueEventHandler.EVENT_SERVER_START_GAME, conns);
			} else {
				midlet.handleEvent(BlueEventHandler.EVENT_SERVER_START_GAME, blueServerBT.connections);
			}
		}
	}

	void completeServerInitialization(boolean isBTReady) {
		midlet.completeServerInitialization(isBTReady);
	}

	public UUID getServiceUUID() {
		return serviceUUID;
	}

	public void connectionReceived(Connection conn) {
		showui();
	}

	public void destroy() {
		blueServerBT.destroy();
	}
}

⌨️ 快捷键说明

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