2012-05-27 146 views
0

我已经创建了与订户和发布者的Java聊天。我试图发送私人消息给特定的用户,当我发送消息所有用户得到它时,我试图取消用户以获取消息,而我正在使用“如果”但它不工作任何想法。监听器onMessage JAVA

else if (tempM[2].equals(chat)) { 
    //send message to every one 
    if (userNameListErea.isSelectionEmpty()) { 
    chatTextErea.append(tempM[0] + ": " + tempM[1] + "\n"); 
    // not send message to your self. 
    } else if (userNameListErea.getSelectedValue().toString().equals(userName)) { 
    chatTextErea.append("Can not sent private to your self \n"); 
    // if its not public and not to ypurself the its private 
    }else { 
    chatTextErea.append(userNameListErea.getSelectedValue() + " send u private: " + 
     tempM[1] + "\n"); 
    } 
} 

也许我错过了正确的命令当你试图使用的确切SMAE机制将消息发送到每一个人,一个sepecific用户从视图阻止用户的消息

回答

0

,你不会得到你正在寻找的结果。

您需要添加逻辑以查看当前用户是否与发送消息的用户相同。根据您发布的exampe,userName是发送者的名字,所以你需要有一个类似的逻辑对接收机:

}else if (userNameListErea.getSelectedValue().toString().equals(currentUserName)) { 
    chatTextErea.append(userNameListErea.getSelectedValue() + " send u private: " + 
    tempM[1] + "\n"); 
} 
+0

工作!!!!!!!! – cfircoo