Receiving fine, but when I call the updateChat() method in the game it won't show up

66 Views Asked by At

I know that the client side of my program is receiving fine because when I system.out.println(message); it shows the message in the cmd prompt. The only problem is that when I call the method to update the chat on the game frame (in the JPanel), the message won't show up. Heres a few snippets of code, see if you can tell my why it wont update.

Client method for receiving packets:

public void receivePackets(int packetID, String line, int colon) throws IOException{
switch(packetID) {
    case 0: //player sending a message
    String token = line.substring(colon+1);
    chatHandler.updateChat(message);
    System.out.println(message);//this prints out
    break;
    case 1: //player position update
    int comma = line.indexOf(",");
    int playerX = Integer.parseInt(line.substring(colon+1, comma));
    int playerY = Integer.parseInt(line.substring(comma+1));
    break;
}
}

ChatHandler method for sending chat:

public void updateChat(String next) {
allChat[4] = allChat[3];
allChat[3] = allChat[2];
allChat[2] = allChat[1];
allChat[1] = allChat[0];
allChat[0] = next;
     System.out.println(next);//this also prints out
}

Here is the catch. I know nothing is wrong with the updateChat method because when I call it from within the ChatHandler class, it updates the chat on the JPanel. It just for some reason won't update the chat when it is called from the Client class. I have even tried using this method within the ChatHandler class:

public void receiveChat(String message) {
    updateChat(message);
}

I hope you can help me. Honestly, this should be working because the println method works, but the update chat method isn't, but oh well, I don't care as long as there is a solution.

1

There are 1 best solutions below

1
mrswadge On

If you are receiving the message, then it is not a socket issue and more likely a repaint issue. Ensure you are setting the text on the JComponent responsible for displaying it. Then, if necessary force a repaint.