I have created java chat with subscriber and publisher. I am trying to send private message to specific user when I send the message all users got it, I have tried to cancel from user to get the message while I am using “IF” but its not working any idea.
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");
}
}
maybe I missing the right command for blocking user from view the message
As you are trying to use the exact smae mechanism for sending a message to everyone and to one sepecific user, you will not get the result you are looking for.
You need to add the logic to see if the current user is the same as the one the message is sent to. Based on the exampe you posted,
userNameis the name of the sender, so you need to have a similar logic for the receiver: