📄 clientlistener.java
字号:
/* I BlueTooth You -- Simple BlueTooth talker Copyright (C) 2007 Jan Tomka, Martin Vysny 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. */package net.sf.btw.ibtu.bluetooth;import java.io.DataInputStream;import javax.microedition.lcdui.Display;import net.sf.btw.btlib.IClientListener;import net.sf.btw.tools.Logger;import net.sf.btw.ibtu.Message;import net.sf.btw.ibtu.ui.HistoryCanvas;/** * Listens for client events and acts accordingly. * * @author Martin Vysny */public final class ClientListener implements IClientListener { /** * Reference to the {@link HistoryCanvas} to append system and user * messages to. */ private final HistoryCanvas canvas; /** * Reference to the {@link Display} to show the error alerts on. * TODO Not used anymore, remove references. */ private final Display disp; /** * Creates new listener. * * @param disp the midlet display * @param canvas the history canvas instance. */ public ClientListener(final Display disp, final HistoryCanvas canvas) { super(); this.canvas = canvas; this.disp = disp; } /** * Handles an error that occured on the client side. Appends a system * message to the history canvas and displays an alert. * * @param clientID * Unused. * @param errorHint * Unused. * @param ex * Exception that is to be handled, containing information * about the error that occured. * * @see net.sf.btw.btlib.IErrorListener#errorOccured(int, int, * java.lang.Exception) */ public void errorOccured(int clientID, int errorHint, boolean listenerError, Exception ex) { canvas.append(new Message(null, "Error occured")); } /** * Handles the disconnection event on the client side. Appends a * system message to the history canvas. * * @see net.sf.btw.btlib.IClientListener#disconnected() */ public void disconnected() { canvas.append(new Message(null, "Disconnected")); // TODO Switch back to the Connector or just remove New command (???) } /** * Handles reception of a message from the server. Reads message from * the stream and appends it to the history canvas. In case the error * occures, appends an error message to thehistory canvas. * * @param message * Unused. * @param messageLength * Unused. * @param stream * Input stream the message is to be read from. * * @see net.sf.btw.btlib.IClientListener#messageArrived(byte[], int, * java.io.DataInputStream) */ public void messageArrived(byte[] message, int messageLength, DataInputStream stream) { try { final Message msg = Message.fromStream(stream); canvas.append(msg); } catch (Exception ex) { Logger.error("Error decoding message", ex); canvas.append(new Message(null, "Error decoding message, discarded")); } } /** * Handles the event of successfull connection establishment to the * server. Appends a system message to the history canvas. * * @see net.sf.btw.btlib.IClientListener#connected() */ public void connected(final byte id) { /* empty */ } public void errorOccured(final byte peerId, final int errorHint, final boolean listenerError, final Exception ex) { }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -