I made a program that opens a database and makes an update, how this update is very long, I've tried to make a new frame where the user could see the state of the update.
The problem is: When I launch the new Thread the structure of the window is created but doesn't show anything else. When the update has finished, then, the window finished to load completely all the content.
What am I doing wrong ?
public class finestra extends Thread{
@Override
public void run(){
label1.setText(getMissatge1());
label1.setHorizontalAlignment(JLabel.CENTER);
label2.setText(getMissatge2());
label2.setHorizontalAlignment(JLabel.CENTER);
label3.setHorizontalAlignment(JLabel.RIGHT);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLayout(new GridLayout(0,1));
frame.setSize(300, 100);
frame.add(label1);
frame.add(label2);
frame.add(label3);
//frame.pack();
frame.setVisible(true);
int temps = 0;
boolean ok = false;
while(ok == false){
temps++;
try{
Thread.sleep(1000);
label1.setText(getMissatge1());
label2.setText(getMissatge2());
label3.setText("Working " + String.valueOf(temps));
}catch (Exception a){
}
}
}
}
And this is the way that i launch the thread:
finestra Finestra = new finestra(); Finestra.start();
Thanks a lot!