当我点击一个群的头像时(该群在我未点之前没有人),客户端会发一个请求告诉服务器我来了这个群,然后服务器接收到了该message就通知,就发个通知给所有的在线好友提示该群有人了(该群头像为亮),并把我的ID和点击的群的ID储存在HASHMAP中,然后再把Hashmap发给客户端,客户端接收到了后,在我的该群的聊天窗口上显示有哪些人在这个群里。我点击该群后,服务器端储存我的ID和该群ID:
temp = (Set<String>) (ManageGroupList.hm.containsKey(ms.getContent())?ManageGroupList.hm.get(ms.getContent ()):new HashSet<Integer>());
temp.add(ms.getSender());
ManageGroupList.hm.put(ms.getContent(),temp);//getcontent()是该群ID服务器给我发送该群有哪些人
ObjectOutputStream oos8 = new ObjectOutputStream(ManageCliThread.getClienThread(ms.getSender()).s.getOutputStream());
Message ms7 = new Message();
ms7.setMessageType(MessageType.messageWhoIsInYourGroup);
ms7.setReceiver(ms.getSender());//sender是点击群头像的那人,也就是我
ms7.setContent(ms.getContent());
ms7.setTellYourGroup(ManageGroupList.hm);
oos8.writeObject(ms7);客户端收到该信息:
ManageGroupList.hm = (HashMap)ms.getTellYourGroup().clone();//客户端也有一个hashmap来复制服务器发过来的hashmap
System.out.println(ManageGroupList.hm);
GroupChat group = new GroupChat(ms.getReceiver(),ms.getContent());
ManageGroupList.hm.clear();显示到我的该群聊天窗口中:public GroupChat(String ownerID,String GroupNo)
{
....//为窗口布局
....
....
temp = (Set<String>) (ManageGroupList.hm.containsKey(GroupNo)?ManageGroupList.hm.get(GroupNo):new HashSet<Integer>());
Iterator it =temp.iterator();
while(it.hasNext())
{
for(int i= 0;i<temp.size();i++)
{
label[i]=it.next().toString()+" is in chatting...";//label[i]是显示谁在该群里的label.
}
}
}现在问题是:为什么用户1登陆后点击群1,(群里显示 1在该群)
用户2登陆后点击群1,(群显示 2 1在该群)
用户2再点击群2,(群显示2 1在该群)!!!用户1根本没点击群2啊
temp = (Set<String>) (ManageGroupList.hm.containsKey(ms.getContent())?ManageGroupList.hm.get(ms.getContent ()):new HashSet<Integer>());
temp.add(ms.getSender());
ManageGroupList.hm.put(ms.getContent(),temp);//getcontent()是该群ID服务器给我发送该群有哪些人
ObjectOutputStream oos8 = new ObjectOutputStream(ManageCliThread.getClienThread(ms.getSender()).s.getOutputStream());
Message ms7 = new Message();
ms7.setMessageType(MessageType.messageWhoIsInYourGroup);
ms7.setReceiver(ms.getSender());//sender是点击群头像的那人,也就是我
ms7.setContent(ms.getContent());
ms7.setTellYourGroup(ManageGroupList.hm);
oos8.writeObject(ms7);客户端收到该信息:
ManageGroupList.hm = (HashMap)ms.getTellYourGroup().clone();//客户端也有一个hashmap来复制服务器发过来的hashmap
System.out.println(ManageGroupList.hm);
GroupChat group = new GroupChat(ms.getReceiver(),ms.getContent());
ManageGroupList.hm.clear();显示到我的该群聊天窗口中:public GroupChat(String ownerID,String GroupNo)
{
....//为窗口布局
....
....
temp = (Set<String>) (ManageGroupList.hm.containsKey(GroupNo)?ManageGroupList.hm.get(GroupNo):new HashSet<Integer>());
Iterator it =temp.iterator();
while(it.hasNext())
{
for(int i= 0;i<temp.size();i++)
{
label[i]=it.next().toString()+" is in chatting...";//label[i]是显示谁在该群里的label.
}
}
}现在问题是:为什么用户1登陆后点击群1,(群里显示 1在该群)
用户2登陆后点击群1,(群显示 2 1在该群)
用户2再点击群2,(群显示2 1在该群)!!!用户1根本没点击群2啊
ManageGroupList.hm.clear();//这步操作你确定需要?感觉很危险
while(it.hasNext())
{
for(int i= 0;i<temp.size();i++)
{
label[i]=it.next().toString()+" is in chatting...";//label[i]是显示谁在该群里的label.}
}
这步操作难道没出现异常?你把it.next()放在for循环里,那while(it.hasNext())还有什么用
int k=0;
while(it.hasNext())
{
String labels = it.next().toString();
label[k]=labels+" is in chatting...";
k++;
}