I have that code
import javax.swing.JFrame;
import javax.swing.JLabel;
public class ChatClient extends JFrame {
public static void main(String[] args) throws InterruptedException {
JFrame frame=new JFrame("chat");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(400,400);
frame.setVisible(true);
frame.setLayout(null);
JLabel label=new JLabel();
label.setText("HOR");
label.setBounds(100,100,100,100);
frame.add(label);
Thread.sleep(1000);
JLabel label1=new JLabel();
label1.setText("SE");
label1.setBounds(100,200,100,100);
frame.add(label1);
}
}
I want write multiple strings in the frame but at different times. The problem is that "hor" is printed correctly, but "se" is printed only if I change the size of the window or if I minimize it. I think "se" is not printed until I update the frame. I know that i can resolve with frame.repaint()
after Thread.sleep()
, but is the more appropriate method?