I'm working on a project written in Java with a Client-Server structure.
My client is made up of Graphical Interfaces with Swing and the server working with multi-threads. But I'm at a point where I can not go through with it. There is an action on the server where it sends a data (String) every 10 seconds to the client. The problem is at the moment when I will receive this data and set it on a label located in a Jframe. I can not get the data and set it at the same time. Here's the snippet where I get the value:
while (cond) {
//Espera ate receber um dado do srv para ler
String line = in.readLine(),pedra;
//Verifica se incia com PEDRA. True = Pego valor, setText
if ( line.startsWith("PEDRA")) {
pedra = line.substring(6));
lblMostraDado.setText(pedra);
//Caso for BINGO fim de jogo
}else if( line.startsWith("BINGO")){
cond = false;
}
I have already done several tests and I have drawn some conclusions. When I run the above code in debug mode the values arrive from the server and are assigned to the label normally, but it is not updated in the window. Now when I remove this while, it only receives once the value of the server and gets the value of the label on the label and is updated on the screen, but I must always take these values until the while stop condition comes.