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

📄 clientreceive.java

📁 企业内部管理系统
💻 JAVA
字号:
package control;

import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;

import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JTextArea;

public class ClientReceive extends Thread {
	public Socket socket;

	public ObjectOutputStream output;

	public ObjectInputStream input;

	JComboBox comboBox;

	JTextArea textArea;

	JLabel showStatus_1;

	public ClientReceive(Socket socket, ObjectOutputStream output,
			ObjectInputStream input, JComboBox comboBox, JTextArea textArea,
			JLabel showStatus_1) {
		this.socket = socket;
		this.output = output;
		this.input = input;
		this.comboBox = comboBox;
		this.textArea = textArea;
		this.showStatus_1 = showStatus_1;
	}

	public void run() {
		while (!socket.isClosed()) {
			try {
				String type = (String) input.readObject();
				if (type.equalsIgnoreCase("系统信息")) {
					String sysmsg = (String) input.readObject();
					textArea.append("系统信息:" + sysmsg);
				} else if (type.equalsIgnoreCase("服务关闭")) {
					output.close();
					input.close();
					socket.close();
					textArea.append("服务器已关闭!" + "\n");
					break;
				} else if (type.equalsIgnoreCase("聊天信息")) {
					String message = (String) input.readObject();
					textArea.append(message);
				} else if (type.equalsIgnoreCase("用户列表")) {
					String userlist = (String) input.readObject();
					String[] usernames = userlist.split("\n");
					comboBox.removeAllItems();
					int i = 0;
					comboBox.addItem("所有人");
					while (i < usernames.length) {
						comboBox.addItem(usernames[i]);
						i++;
					}
					comboBox.setSelectedIndex(0);
					showStatus_1.setText(usernames.length + "人");
				}
			} catch (Exception e) {
				// TODO: handle exception
				e.printStackTrace();
			}
		}
	}

}

⌨️ 快捷键说明

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