So, as can be seen from my code below, I'm trying to change my JLabel text to the following values after the following time increments in a java swing GUI, but when I press the start button. Everything just freezes and the Label goes from the original text to the final text, "The game will continue for 20 seconds and now begins", how can I show all the intermediate texts too with the appropriate time delays?
JLabel displayNum=new JLabel("Welcome to Mania Marauders");
JButton b=new JButton("start");
b.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
displayNum.setText("Soon, where this text appears, a number will appear");
try {
Thread.sleep(1100);
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
displayNum.setText("This number correlates to a button below with the same number");
try {
Thread.sleep(700);
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
displayNum.setText("If you're able to hit the right button before the number displayed changes, you get a point");
try {
Thread.sleep(2000);
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
displayNum.setText("The game will continue for 20 seconds and now begins");
}
});