I try to write a Tic Tac Toe game between 2 devices with graphics and everything, but I have a problem. After I press a button I change its icon and then send the data via a socket and use blocking command to get the response. My problem is that I can see the change in the button's icon only after I get the response from the socket. Does anyone know what to do?
I learned sockets in python, and only recently I decided to try writing a program with sockets in java, so I don't have much experience in Java. I tried to delay the program before I wait for response, and to get 2 responses(one is automatic), but they both failed. I also tried to use timer to update the button's icons every tick, also didn't work.
That's the relevant part from my code
Socket sock;
PrintWriter pr;
InputStreamReader in;
BufferedReader bf;
public void click(int x, int y)
{
buttons[x][y].setIcon(new ImageIcon("C:\\Users\\shaked\\Desktop\\red_Pin.jpg"));
String msg = (char)x + "," + (char)y;
try {
System.out.println("SLEEPING");
Thread.sleep(1000);
}
catch(InterruptedException ex)
{
Thread.currentThread().interrupt();
}
pr.println(msg);
pr.flush();
String enemy_move = bf.readLine();
}