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

📄 listenerthread.java

📁 用java写的简单聊天器....初学者有帮助的
💻 JAVA
字号:
package com.hanhf.java;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.Socket;

import javax.swing.JTextArea;

public class ListenerThread extends Thread {
	private JTextArea txtChatInfo = null;

	private BufferedReader in = null;

	private boolean isRunning = true;

	public ListenerThread(Socket socket, JTextArea txtChatInfo) {
		try {
			in = new BufferedReader(new InputStreamReader(socket
					.getInputStream()));
		} catch (IOException ex) {
		}
		this.txtChatInfo = txtChatInfo;
	}

	public void run() {
		while (isRunning) {
			try {
				txtChatInfo.append("对方说:" + in.readLine() + "\r\n");
				Thread.sleep(500);
			} catch (Exception ex) {
			}
		}
	}

	public void end() {
		try {
			in.close();
		} catch (IOException ex) {
		}
		isRunning = false;
	}
}

⌨️ 快捷键说明

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