亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? pcclientcomm.java

?? 用Java開發手機藍牙程序。要先安裝J2ME
?? JAVA
字號:
package example.simple;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Vector;

import javax.bluetooth.BluetoothStateException;
import javax.bluetooth.DeviceClass;
import javax.bluetooth.DiscoveryAgent;
import javax.bluetooth.DiscoveryListener;
import javax.bluetooth.LocalDevice;
import javax.bluetooth.RemoteDevice;
import javax.bluetooth.ServiceRecord;
import javax.bluetooth.UUID;
import javax.microedition.io.Connector;
import javax.microedition.io.StreamConnection;
import javax.swing.BorderFactory;
import javax.swing.DefaultListCellRenderer;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.SwingUtilities;

/**
 * A class that demonstrates Bluetooth communication between client mode PC and
 * server mode device through serial port profile. The example uses JSR-82 API.
 * 
 * @see <a href="http://sourceforge.net/projects/bluecove/">BlueCove - a JSR-82
 *      implementation</a>
 */
public class PCClientCOMM implements DiscoveryListener {

	/*-
	 * ================
	 * Bluetooth Client
	 * ================
	 * 
	 * This example application is a straightforward implementation of 
	 * making a connection throught bluetooth link and using it. 
	 * 
	 * 
	 * Usage
	 * =====
	 * 
	 * Once the system is started the information area is filled with logging
	 * information. Wait until combo box is enabled (if there's any bluetooth 
	 * device around) and select a device from the combo box. A connection 
	 * is constructed to selected device after selection. 
	 * 
	 * After connection is constructed succesfully the application 
	 * operates as an echo client, i.e., everything that is read is written 
	 * back to the server. All information is also written into the information 
	 * area.
	 * 
	 * 
	 * How it Works
	 * ============
	 * 
	 * The example consist of three different operations. Operations need to 
	 * be executed in the dependency order. 
	 * 
	 * 1) *Inquiry method* is used to search all available devices. The combo 
	 *    box's data model is filled with found bluetooth devices.
	 *     
	 * 2) *Service search* is used to search serial port profile service from the
	 *    selected device. The search is started after the user selects the
	 *    device from the combo box.
	 *    
	 * 3) *Stream handling* communicates with the server through the bluetooth 
	 *    link. This example operates in echo loop until stop token is found.
	 * 
	 * 
	 * Special Debug Mode
	 * ==================
	 * 
	 * There's a special debug mode which speeds up development by skipping the
	 * inquiry method to resolve the remote device. In the debug mode the device's 
	 * bluetooth address is provided by the developer.
	 */

	/*-
	 * 
	 *  ---- Debug attributes ----
	 */

	static final boolean DEBUG = false;

	static final String DEBUG_address = "0013FDC157C8"; // N6630

	/*-
	 * 
	 *  ---- Bluetooth attributes ----
	 */
	protected UUID uuid = new UUID(0x1101); // serial port profile

	protected int inquiryMode = DiscoveryAgent.GIAC;

	protected int connectionOptions = ServiceRecord.NOAUTHENTICATE_NOENCRYPT;

	/*-
	 * 
	 *  ---- Echo loop attributes ----
	 */

	protected int stopToken = 255;

	/*-
	 * 
	 *  ---- GUI attributes ----
	 */

	protected JTextArea infoArea = null;

	protected Vector deviceList = new Vector();

	protected JComboBox combo;

	protected ItemListener comboSelectionListener = new ItemListener() {
		public void itemStateChanged(ItemEvent e) {
			startServiceSearch((RemoteDevice) combo.getSelectedItem());
			combo.removeItemListener(this);
			combo.setEnabled(false);
		}
	};

	public PCClientCOMM() {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {

				createGUI();

				if (DEBUG) // skip inquiry in debug mode
					startServiceSearch(new RemoteDevice(DEBUG_address) {
					});
				else
					startDeviceInquiry();
			}
		});
	}

	/*-
	 *   -------  Device inquiry section -------
	 */

	private void startDeviceInquiry() {
		try {
			deviceList.removeAllElements();
			log("Start inquiry method - this will take few seconds...");
			getAgent().startInquiry(inquiryMode, this);
		} catch (Exception e) {
			log(e);
		}
	}

	public void deviceDiscovered(RemoteDevice btDevice, DeviceClass cod) {
		log("A device discovered (" + getDeviceStr(btDevice) + ")");
		deviceList.addElement(btDevice);
		if (!combo.isEnabled()) {
			combo.setEnabled(true);
			combo.addItemListener(comboSelectionListener);
		}
	}

	public void inquiryCompleted(int discType) {
		log("Inquiry compeleted. Please select device from combo box.");
	}

	/*-
	 *   -------  Service search section -------
	 */

	private void startServiceSearch(RemoteDevice device) {
		try {
			log("Start search for Serial Port Profile service from "
					+ getDeviceStr(device));
			UUID uuids[] = new UUID[] { uuid };
			getAgent().searchServices(null, uuids, device, this);
		} catch (Exception e) {
			log(e);
		}
	}

	/**
	 * This method is called when a service(s) are discovered.This method starts
	 * a thread that handles the data exchange with the server.
	 */
	public void servicesDiscovered(int transId, ServiceRecord[] records) {
		log("Service discovered.");
		for (int i = 0; i < records.length; i++) {
			ServiceRecord rec = records[i];
			String url = rec.getConnectionURL(connectionOptions, false);
			handleConnection(url);
		}
	}

	public void serviceSearchCompleted(int transID, int respCode) {
		String msg = null;
		switch (respCode) {
		case SERVICE_SEARCH_COMPLETED:
			msg = "the service search completed normally";
			break;
		case SERVICE_SEARCH_TERMINATED:
			msg = "the service search request was cancelled by a call to DiscoveryAgent.cancelServiceSearch()";
			break;
		case SERVICE_SEARCH_ERROR:
			msg = "an error occurred while processing the request";
			break;
		case SERVICE_SEARCH_NO_RECORDS:
			msg = "no records were found during the service search";
			break;
		case SERVICE_SEARCH_DEVICE_NOT_REACHABLE:
			msg = "the device specified in the search request could not be reached or the local device could not establish a connection to the remote device";
			break;
		}
		log("Service search completed - " + msg);

		if (respCode == SERVICE_SEARCH_ERROR)
			startDeviceInquiry();
	}

	/*-
	 *   -------  The actual connection handling. -------
	 */

	private void handleConnection(final String url) {
		Thread echo = new Thread() {
			public void run() {
				StreamConnection stream = null;
				try {
					log("Connecting to server by url: " + url);
					stream = (StreamConnection) Connector.open(url);

					log("Bluetooth stream open.");
					InputStream in = stream.openInputStream();
					OutputStream out = stream.openOutputStream();
					log("Start echo loop.");
					while (true) {
						int r = in.read();
						log("Read " + r + ", write it back.");
						out.write(r);
						out.flush();
						if (r == stopToken) {
							log("Stop echo loop.");
							break;
						}
					}
				} catch (IOException e) {
					log(e);
				} finally {
					log("Bluetooth stream closed.");
					if (stream != null) {
						try {
							stream.close();
						} catch (IOException e) {
							log(e);
						}
					}
				}
			}
		};
		echo.start();
	}

	/*-
	 *   -------  Graphic User Interface section -------
	 */

	private void createGUI() {
		JFrame.setDefaultLookAndFeelDecorated(true);
		JFrame frame = new JFrame("Bluetooth Client");
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.getContentPane().setLayout(new BorderLayout());
		frame.setSize(new Dimension(400, 400));

		JPanel margin = new JPanel(new BorderLayout());
		margin.setBorder(BorderFactory.createEmptyBorder(15, 15, 15, 15));
		frame.getContentPane().add(margin);

		infoArea = new JTextArea();
		infoArea.setLineWrap(true);
		JScrollPane pane = new JScrollPane(infoArea,
				JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
				JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
		margin.add(pane);

		combo = new JComboBox(this.deviceList);
		combo.setEnabled(false);
		combo.setEditable(false);
		combo.setSelectedItem(null);
		combo.setRenderer(new DefaultListCellRenderer() {
			public Component getListCellRendererComponent(JList list,
					Object value, int index, boolean isSelected,
					boolean cellHasFocus) {
				RemoteDevice remote = (RemoteDevice) value;
				if (remote == null)
					setText("No remote devices available.");
				else
					setText(getDeviceStr(remote));
				return this;
			}
		});
		margin.add(combo, BorderLayout.SOUTH);

		frame.setVisible(true);
	}

	private void log(String msg) {
		infoArea.insert(msg + "\n", infoArea.getDocument().getLength());
	}

	private void log(Exception e) {
		log(e.getMessage());
		e.printStackTrace();
	}

	/*-
	 *   -------  Utils section - contains utility functions -------
	 */

	private DiscoveryAgent getAgent() {
		try {
			return LocalDevice.getLocalDevice().getDiscoveryAgent();
		} catch (BluetoothStateException e) {
			log(e);
			log("ERROR detected and all operations stopped.");
			throw new Error("No discovery agent available.");
		}
	}

	private String getDeviceStr(RemoteDevice btDevice) {
		return getFriendlyName(btDevice) + " - 0x"
				+ btDevice.getBluetoothAddress();
	}

	private String getFriendlyName(RemoteDevice btDevice) {
		try {
			return btDevice.getFriendlyName(false);
		} catch (IOException e) {
			return "no name available";
		}
	}

	/*-
	 *   -------  Bootstrap section, i.e., main method -------
	 */

	public static void main(String[] args) {
		new PCClientCOMM();
	}

}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美精选一区二区| 国产三级欧美三级日产三级99| 蜜臀久久99精品久久久画质超高清| 精品精品国产高清a毛片牛牛| 99久久综合精品| 美女视频黄久久| 亚洲美女少妇撒尿| 日韩精品一区二区三区蜜臀| 91一区一区三区| 国产精品综合一区二区| 亚洲成人自拍网| 亚洲久草在线视频| 国产人伦精品一区二区| 91精品国产综合久久久久久| 色综合久久99| 99久久精品免费观看| 久久www免费人成看片高清| 亚洲大尺度视频在线观看| 亚洲视频一二三区| 中文字幕日韩精品一区| 久久久三级国产网站| 88在线观看91蜜桃国自产| 一本大道av一区二区在线播放| 国产成人久久精品77777最新版本| 美女诱惑一区二区| 三级在线观看一区二区 | 欧美大尺度电影在线| 欧洲中文字幕精品| 一本高清dvd不卡在线观看| 成人18精品视频| 成人国产精品免费观看动漫| 国内精品久久久久影院一蜜桃| 久久狠狠亚洲综合| 日韩成人av影视| 午夜不卡av在线| 亚洲电影欧美电影有声小说| 亚洲一区二区三区视频在线| 亚洲欧洲www| 最新中文字幕一区二区三区| 中文乱码免费一区二区| 国产日韩欧美高清| 欧美国产成人在线| 国产精品美日韩| 中文欧美字幕免费| 日韩美女视频一区| 尤物av一区二区| 亚洲成人综合视频| 麻豆成人综合网| 国产高清精品在线| av中文字幕亚洲| 91丨九色porny丨蝌蚪| 一本大道久久a久久精品综合| 91传媒视频在线播放| 欧美在线高清视频| 欧美视频一区二区三区| 欧美天堂一区二区三区| 这里只有精品免费| 亚洲精品在线网站| 国产欧美一区二区精品秋霞影院 | 日韩精品中文字幕在线一区| 精品国产污污免费网站入口| 久久久亚洲国产美女国产盗摄| 国产精品久久久久一区| 亚洲男人天堂av网| 蜜桃视频免费观看一区| 国产乱子轮精品视频| 99精品国产视频| 欧美欧美欧美欧美首页| 久久噜噜亚洲综合| 亚洲私人影院在线观看| 日本特黄久久久高潮| 国产精品18久久久| 色菇凉天天综合网| 日韩一区二区三区电影在线观看| 久久综合精品国产一区二区三区 | 日韩久久久精品| 18欧美乱大交hd1984| 五月婷婷综合网| 懂色一区二区三区免费观看| 日本久久电影网| 精品粉嫩超白一线天av| 亚洲欧美日韩精品久久久久| 奇米色777欧美一区二区| 粉嫩aⅴ一区二区三区四区五区| 欧美三级蜜桃2在线观看| 久久免费精品国产久精品久久久久| 国产精品久久久久一区二区三区 | 亚洲一区二区在线观看视频 | 国产精品乱码一区二三区小蝌蚪| 一区二区三区 在线观看视频| 久久国产精品99精品国产| 91美女视频网站| 久久色中文字幕| 亚洲午夜电影在线| 成人av动漫在线| 欧美成人综合网站| 夜夜爽夜夜爽精品视频| 国产剧情一区在线| 欧美三级日韩三级国产三级| 日本一二三四高清不卡| 麻豆91小视频| 91成人网在线| 欧美国产日韩精品免费观看| 日韩成人免费看| 欧美视频日韩视频在线观看| 国产精品成人一区二区艾草 | 久热成人在线视频| 在线欧美小视频| 国产精品久久久久久久久免费丝袜 | 美女视频一区在线观看| 91女厕偷拍女厕偷拍高清| 精品国产污网站| 五月天亚洲婷婷| 欧美性猛片aaaaaaa做受| 国产精品乱人伦| 国产成人精品免费在线| 欧美一级视频精品观看| 亚洲成a人片在线观看中文| 91蜜桃在线观看| 中文字幕一区二区不卡| 国产永久精品大片wwwapp| 91精品欧美一区二区三区综合在| 一区二区高清免费观看影视大全| 99精品欧美一区二区三区综合在线| 国产视频一区在线播放| 老司机精品视频一区二区三区| 在线不卡a资源高清| 一个色综合av| 欧美伊人精品成人久久综合97| 自拍偷拍亚洲激情| www.欧美亚洲| 亚洲国产精品传媒在线观看| 国产精品一区二区久激情瑜伽| 日本一区二区三区在线不卡| 国产亚洲一区二区三区| 免播放器亚洲一区| 欧美嫩在线观看| 亚洲影视资源网| 欧美在线小视频| 亚洲一区在线看| 欧美日韩一区二区不卡| 亚洲成人精品一区二区| 欧美精品在线一区二区三区| 亚洲第一av色| 日韩欧美一二三四区| 久久国内精品自在自线400部| 精品999在线播放| 国产呦精品一区二区三区网站| 国产日韩欧美高清| 91小宝寻花一区二区三区| 亚洲同性同志一二三专区| 色婷婷av一区二区三区大白胸 | 日韩美女精品在线| 在线看日韩精品电影| 亚洲国产日韩av| 制服丝袜中文字幕一区| 久久精品国产精品青草| 国产婷婷一区二区| 一本色道久久综合亚洲91| 午夜av电影一区| 久久免费偷拍视频| 91视频xxxx| 日韩精品高清不卡| 久久久久国产成人精品亚洲午夜| 不卡的电影网站| 日韩中文字幕1| 国产日韩精品一区| 亚洲国产精品t66y| 91免费国产在线| 日本v片在线高清不卡在线观看| 欧美不卡在线视频| www.亚洲免费av| 丝袜a∨在线一区二区三区不卡| 精品国产自在久精品国产| 成人黄色777网| 亚洲成国产人片在线观看| 2017欧美狠狠色| 91福利视频在线| 国产精品一二三| 亚洲国产综合在线| 精品国产一区二区三区av性色| 91视频在线观看| 久久草av在线| 亚洲激情图片小说视频| 精品电影一区二区三区| 91久久国产最好的精华液| 久久激情综合网| 亚洲午夜精品久久久久久久久| 久久先锋影音av鲁色资源网| 91福利在线看| 国产大陆精品国产| 日本欧美一区二区在线观看| 中文字幕欧美国产| 91精品国产综合久久久久| 99久久精品免费看国产免费软件| 久久精品国产在热久久| 洋洋av久久久久久久一区| 中文一区一区三区高中清不卡| 欧美高清激情brazzers| 99国产精品久|