📄 msgprocess.java
字号:
import java.awt.SystemTray;
import java.awt.Toolkit;
import java.awt.Image;
import java.awt.TrayIcon;
import java.awt.AWTException;
import javax.swing.ImageIcon;
import javax.swing.JList;
class MsgProcess implements Runnable
{
private String []strarray;
private int temptag;
private Login login=null;
private SendMsg sm=null;
private ReceivMsg rm=null;
private MsgVector []msgvector; //消息列表
private MsgVector []msgvectorend;
private int []numofmsg;
private ListCellInfo friendsvector=new ListCellInfo(); //好友列表
private ListCellInfo friendsvectorend=new ListCellInfo();
private int numoffriend; //好友个数
private int numofonline;
private GroupVector groupvector=new GroupVector(); //群列表
private GroupVector groupvectorend=new GroupVector();
private int numofgroup; //群个数
private ChatMsg chatmsg=new ChatMsg(); //收到的聊天消息
private ChatMsg chatmsgend=new ChatMsg();
private int numofchatmsg=0;
public MsgProcess(String tempreceiv,SendMsg sm,Login login,ReceivMsg rm)
{
strarray=tempreceiv.split("\\|");
temptag=Integer.parseInt(strarray[2]);
this.login=login;
this.sm=sm;
this.msgvector=sm.msgvector;
this.msgvectorend=sm.msgvectorend;
this.numofmsg=sm.numofmsg;
this.friendsvector=rm.friendsvector;
this.friendsvectorend=rm.friendsvectorend;
this.numoffriend=rm.numoffriend;
this.numofonline=rm.numofonline;
this.groupvector=rm.groupvector;
this.groupvectorend=rm.groupvectorend;
this.numofgroup=rm.numofgroup;
this.chatmsg=rm.chatmsg;
this.chatmsgend=rm.chatmsgend;
this.numofchatmsg=rm.numofchatmsg;
}
public void start()
{
Thread t=new Thread(this);
t.start();
}
public void run()
{
if(strarray[1].equals("0"))
{
//无需回复
switch(temptag)
{
case 0://服务端已收到客户端发送的消息(消息格式:"时间标志|回复标志|类型标志",执行以下操作:
////////////////////////////////////从该消息从已发送列表中删除!
deleteSendedMsg(strarray[0]);
break;
case 1://服务端返回的用户登录验证消息(消息格式:"时间标志|回复标志|类型标志|是否通过验证|不通过验证的原因")
deleteSendedMsg(strarray[0]);
if(strarray[3].equals("0"))//未通过验证
{
login.setInfo(strarray[4]); //如果strarray[4]=unamewrong,表示用户名错误,passwdwrong表示密码错误
}
else //通过验证(登录成功)
{
login.setInfo("success");
}
break;
case 2://服务端返回的好友列表(消息格式:"时间标志|回复标志|类型标志|好友ID,好友昵称,好友头像,好友IP,好友端口,在线于否;repeat")
deleteSendedMsg(strarray[0]);
addFriends(strarray[3]); //生成好友列表
requestGroups(); //获得好友列表后请求群列表
//<--------显示好友列表-------->
break;
case 3://服务端返回的群列表(消息格式:"时间标志|回复标志|类型标志|群ID,群名称,群创建者,群介绍;repeat")
deleteSendedMsg(strarray[0]);
addGroups(strarray[3]); //生成群列表
//<----------显示群列表------------->
break;
case 4://服务端返回的群成员列表(消息格式:"时间标志|回复标志|类型标志|群ID|用户ID1,用户ID2,……")
deleteSendedMsg(strarray[0]);
setGroupMembers(strarray[3],strarray[4]);
//<-------------显示群成员列表------------>
break;
case 5://接收服务器设置(消息格式:未定)
//<-------------具体未定----------------->
break;
case 6:
break;
default:break;
}
}
else if(strarray[1].equals("1"))
{
//需回复
switch(temptag)
{
case 0://服务端发来的在线查询消息(消息格式:"时间标志|回复标志|类型标志")
String msg0=strarray[0]+"|0|0";
sm.setMsg(msg0, login.server_port, login.server_addr,true,false);
break;
case 1://服务端发来的好友上线消息(消息格式:"时间标志|回复标志|类型标志|好友ID|好友姓名|好友头像|好友介绍|好友IP|好友端口")
String msg1=strarray[0]+"|0|0";
sm.setMsg(msg1, login.server_port, login.server_addr, true,false);
setFriendState(strarray[3],true);
//<-----------------更新好友列表--------------->
break;
case 2://好友下线(消息格式:"时间标志|回复标志|类型标志|好友ID")
String msg2=strarray[0]+"|0|0";
sm.setMsg(msg2, login.server_port, login.server_addr, false,false);
setFriendState(strarray[3],false);
//<----------------刷新好友列表--------------->
break;
case 3://收到好友发来的消息(时间标志|回复标志|类别标志|来源(用户名)|去向(用户名)|消息主体|来源地址|来源端口
ChatWindow cw=new ChatWindow(strarray,login);
//addChatMsg(strarray);
break;
}
}
}
/////////////////////////////////请求群列表/////////////////////
private void requestGroups()
{
String msg="1|4|"+login.local_username+"|"+login.local_addr+"|"+login.local_port;
sm.setMsg(msg, login.server_port, login.local_addr, false, false);
}
///////////////////////////////////添加聊天消息///////////////////
private synchronized void addChatMsg(String []strarray)
{
ChatMsg cm=new ChatMsg(strarray[3],strarray[6],strarray[4],Integer.parseInt(strarray[5]));
if(numofchatmsg==0) //第一个节点
{
chatmsg.next=cm;
chatmsgend=cm;
}
else
{
chatmsgend.next=cm;
chatmsgend=cm;
}
}
private void returnNoneReplyMsg(String timetag,String addr,int port)
{
// String msg=""
}
public synchronized void deleteSendedMsg(String serialnum)
{
MsgVector sp_current=null;
sp_current=msgvector[1];
while(sp_current.next!=null)
{
if(sp_current.next.time==Integer.parseInt(serialnum))
{
sp_current.next=sp_current.next.next;
numofmsg[1]--; //删除一个已发送消息
break;
}
else
{
sp_current=sp_current.next;
}
}
}
public synchronized void addFriends(String strarray3)
{
String []FriendInfo=strarray3.split("\\;");
for(int i=0;i<FriendInfo.length;i++) //好友个数
{
String []oneInfo=FriendInfo[i].split("\\,");
ImageIcon ii=null;
if(oneInfo[5].equals("离线"))
ii=Function.GetPixels(Function.getImageIcon(this,oneInfo[2]),40,40);
else
ii=Function.getImageIcon(this,oneInfo[2]);
ListCellInfo lci=new ListCellInfo(ii,oneInfo[0],oneInfo[1],oneInfo[3],Integer.parseInt(oneInfo[4]),oneInfo[5]);
login.qqbar.dlm_Friend.addElement(lci);
}
login.qqbar.setTitle("企业QQ客户端");
}
public synchronized void setFriendState(String strarray3,boolean state)
{
}
public synchronized void addGroups(String strarray3)
{
String []groups=strarray3.split("\\;");
numofgroup=groups.length;
for(int i=0;i<numofgroup;i++) //添加好友节点
{
String []groupinfo=groups[i].split("\\,");
GroupVector gv=new GroupVector(groupinfo[0],groupinfo[1],groupinfo[2],groupinfo[3]);
if(i==0)
{
groupvector.next=gv;
groupvectorend=gv;
}
else
{
groupvectorend.next=gv;
groupvectorend=gv;
}
}
}
public synchronized void setGroupMembers(String groupid,String members)
{
GroupVector sp_current=null;
sp_current=groupvector;
while(sp_current.next!=null)
{
if(sp_current.next.groupid.equals(groupid))
{
sp_current.next.groupmembers=members;
break;
}
else
{
sp_current=sp_current.next;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -