clientreceive.java

来自「基于netbeans的java桌面应用程序合集」· Java 代码 · 共 57 行

JAVA
57
字号
/* * To change this template, choose Tools | Templates * and open the template in the editor. */package org.Adam;import javax.swing.*;import java.io.*;import java.net.*;/** * * @author Administrator */public class ClientReceive extends Thread{    JComboBox jComboBox;    JTextArea jTextArea;    Socket socket;    ObjectInputStream input;    ObjectOutputStream output;    JTextField showStatus;    public ClientReceive(Socket socket,ObjectOutputStream output,ObjectInputStream input,            JComboBox jComboBox,JTextArea jTextArea,JTextField showStatus){        this.input=input;        this.output=output;        this.jComboBox=jComboBox;        this.jTextArea=jTextArea;        this.showStatus=showStatus;        this.socket=socket;    }    public void run(){        while(!socket.isClosed()){            try{                String type=(String)input.readObject();                if(type.equalsIgnoreCase("系统信息")){                    String sysmsg=(String)input.readObject();                    this.jTextArea.append("系统信息"+sysmsg);                }else if(type.equalsIgnoreCase("聊天信息")){                    String message=(String)input.readObject();                    this.jTextArea.append(message);                }else if(type.equalsIgnoreCase("用户列表")){                    String userlist=(String)input.readObject();                    String usernames[]=userlist.split("\n");                    this.jComboBox.removeAllItems();                    this.jComboBox.addItem("ALL");                    for(int i=0;i<usernames.length;i++){                        this.jComboBox.addItem(usernames[i]);                    }                    this.jComboBox.setSelectedIndex(0);                    this.showStatus.setText("在线用户 " + usernames.length + " 人");                }            }catch(Exception e){                e.getMessage();            }                    }    }}

⌨️ 快捷键说明

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