📄 serverreceivethread.java
字号:
int userCount = userInfoList.getUserCount();//得到链表元素的个数 int testEnd = 0; while(testEnd < userCount){//遍历用户链表 SingleUserMegData node = userInfoList.find(testEnd); if(node == null){ testEnd++; continue; } node.dataOut.writeObject("图片"); node.dataOut.flush(); node.dataOut.writeObject(icon); node.dataOut.flush(); node.dataOut.writeObject(node.userName); node.dataOut.flush(); testEnd++; } } private void sendWarningToAll(String warning){ int userCount = userInfoList.getUserCount();//得到链表元素的个数 int testEnd = 0; while(testEnd < userCount){//遍历用户链表 SingleUserMegData node = userInfoList.find(testEnd); if(node == null){ testEnd++; continue; } try{//发送聊天信息内容 node.dataOut.writeObject("警告"); node.dataOut.flush(); node.dataOut.writeObject(warning); node.dataOut.flush(); }catch(Exception e){ System.out.println("发送聊天信息内容失败!" + e); } testEnd++; } } private void sendLeaveToAll(String leave,String userName){ int userCount = userInfoList.getUserCount();//得到链表元素的个数 int testEnd = 0; while(testEnd < userCount){//遍历用户链表 SingleUserMegData node = userInfoList.find(testEnd); if(node == null){ testEnd++; continue; } try{//发送聊天信息内容 node.dataOut.writeObject("下线"); node.dataOut.flush(); node.dataOut.writeObject(leave); node.dataOut.flush(); node.dataOut.writeObject(userName); node.dataOut.flush(); }catch(Exception e){ System.out.println("发送聊天信息内容失败!" + e); } testEnd++; } } public void sendUserListToAll() {//像所有用户发送用户列表 String userList = ""; int userCount = userInfoList.getUserCount();//得到在线用户的个数 int testEnd = 0; while(testEnd < userCount){//遍历用户列表,组成用户列表串 SingleUserMegData node = userInfoList.find(testEnd); if(node == null){ testEnd++; continue; } userList += node.userName; userList += '\n'; testEnd++; } testEnd = 0; while(testEnd < userCount){//遍历链表,依次发送用户列表信息 SingleUserMegData node = userInfoList.find(testEnd); if(node == null){ testEnd++; continue; } try{ //发送用户列表标识 node.dataOut.writeObject("用户列表"); node.dataOut.flush(); //发送用户列表内容 node.dataOut.writeObject(userList); node.dataOut.flush(); }catch(Exception e){e.printStackTrace();} testEnd++; } } public void sendObject(MyTextPane chatMeg, SingleUserMegData clientData,UserInfoList userInfoList, JComboBox userOnlineList){ this.chatMeg = chatMeg; this.clientData = clientData; this.userInfoList = userInfoList; this.userOnlineList = userOnlineList; isStop = false; } public void DelUser(SingleUserMegData delUser){ String kickUserStr = "用户" + delUser.userName + "被踢!" + "\n"; int userCount = userInfoList.getUserCount(); int testEnd = 0; userOnlineList.removeAllItems(); userOnlineList.addItem("所有人"); userInfoList.delete(delUser); while(testEnd < userCount){ delUser = userInfoList.find(testEnd); if(delUser == null){ testEnd++ ; continue; } userOnlineList.addItem(delUser.userName); testEnd++; } chatMeg.append(Color.RED,kickUserStr); } private void receiveMeg() throws IOException, ClassNotFoundException{ //读取发送对象 toSomebody = (String)clientData.dataIn.readObject(); //读取发送时间 date = (String)clientData.dataIn.readObject(); //读取发送状态 sendStatus = (String)clientData.dataIn.readObject(); //读取发送动作 sendAction = (String)clientData.dataIn.readObject(); //读取信息内容 message = (String)clientData.dataIn.readObject(); //读取发送过来的聊天信息字体颜色内容 color = (Color)clientData.dataIn.readObject(); } private void sendChatMeg(){ int userCount = userInfoList.getUserCount();//得到链表元素的个数 int testEnd = 0; while(testEnd < userCount){//遍历用户链表 SingleUserMegData node = userInfoList.find(testEnd); if(node == null){ testEnd++; continue; } try{//发送聊天信息内容 node.dataOut.writeObject("聊天信息"); node.dataOut.flush(); if(testEnd < 1){ chatMeg.append(Color.LIGHT_GRAY,"\n"+"[聊天信息]"); } //发送用户名 node.dataOut.writeObject(clientData.userName); node.dataOut.flush(); if(testEnd < 1){ chatMeg.append(Color.BLUE,clientData.userName); } //发送动作 node.dataOut.writeObject(sendAction); node.dataOut.flush(); if(testEnd < 1){ chatMeg.append(Color.black,sendAction); } node.dataOut.writeObject("对"); node.dataOut.flush(); if(testEnd < 1){ chatMeg.append(Color.black,"对"); } //发送接受信息的对象 node.dataOut.writeObject(toSomebody); node.dataOut.flush(); if(testEnd < 1){ chatMeg.append(Color.blue,toSomebody); } node.dataOut.writeObject("说"); node.dataOut.flush(); if(testEnd < 1){ chatMeg.append(Color.BLACK,"说"); } //发送信息时间 node.dataOut.writeObject(date); node.dataOut.flush(); if(testEnd < 1){ chatMeg.append(Color.LIGHT_GRAY,date + "\n"); } //发送状态 node.dataOut.writeObject(sendStatus); node.dataOut.flush(); if(testEnd < 1){ chatMeg.append(Color.lightGray,sendStatus); } //发送信息内容 node.dataOut.writeObject(message); node.dataOut.flush(); if(testEnd < 1){ chatMeg.append(Color.BLUE,message + "\n"); } if(color != null){ //发送聊天信息内容的字体颜色 node.dataOut.writeObject(color); node.dataOut.flush(); } }catch(Exception e){ System.out.println("发送聊天信息内容失败!" + e); } testEnd++; } } private void smallChatToYou(){//把悄悄话发送给自己 try{//发送聊天信息标识 clientData.dataOut.writeObject("聊天信息"); clientData.dataOut.flush(); //发送用户名 clientData.dataOut.writeObject(clientData.userName); clientData.dataOut.flush(); //发送动作 clientData.dataOut.writeObject(sendAction); clientData.dataOut.flush(); clientData.dataOut.writeObject("对"); clientData.dataOut.flush(); //发送接受信息的对象 clientData.dataOut.writeObject(toSomebody); clientData.dataOut.flush(); clientData.dataOut.writeObject("说"); clientData.dataOut.flush(); //发送信息时间 clientData.dataOut.writeObject(date); clientData.dataOut.flush(); //发送状态 clientData.dataOut.writeObject(sendStatus); clientData.dataOut.flush(); //发送信息内容 clientData.dataOut.writeObject(message); clientData.dataOut.flush(); if(color != null){ //发送聊天信息内容的字体颜色 clientData.dataOut.writeObject(color); clientData.dataOut.flush(); } }catch(Exception e){} } private void smallChat() throws IOException{//把悄悄话发送给别人 SingleUserMegData node = userInfoList.find(toSomebody); if(node != null){ //发送聊天信息标识 node.dataOut.writeObject("聊天信息"); node.dataOut.flush(); //发送用户名 node.dataOut.writeObject(clientData.userName); node.dataOut.flush(); //发送动作 node.dataOut.writeObject(sendAction); node.dataOut.flush(); node.dataOut.writeObject("对"); node.dataOut.flush(); //发送接受信息的对象 node.dataOut.writeObject(toSomebody); node.dataOut.flush(); node.dataOut.writeObject("说"); node.dataOut.flush(); //发送信息时间 node.dataOut.writeObject(date); node.dataOut.flush(); //发送状态 node.dataOut.writeObject(sendStatus); node.dataOut.flush(); //发送信息内容 node.dataOut.writeObject(message); node.dataOut.flush(); if(color != null){ //发送聊天信息内容的字体颜色 node.dataOut.writeObject(color); node.dataOut.flush(); } } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -