I´ve been trying to make a multiple choice question game using swing elements, I am just using a JTextArea to show the questions and four JButtons for the options.
I would like that every time the user answer a question the correct answer is shown by changing the background color of the JButton with the correct answer.
I am using a MVC design pattern so each time the user clicks the options JButtons the actionPerformed method calls a method in the interface that sets the background color of the JButton, sleeps the thread for one second and then it sets the background to the default color.
Everything seems to be right however when a run the program the graphic interface doesn't change the background color, although you can see the thread sleep.
If someone could help me solve this problem i would be very grateful, I include the code of all the described methods.
public void showCorrectAnswer (int index)
{
//JButtons array
options[index].setBackground(Color.green);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
options[index].setBackground(defaultColor);
}
ActionPerformed code of option buttons:
public void actionPerformed(ActionEvent e)
{
JButton source = (JButton) e.getSource();
int index =controller.getTheModel().getIndexWereTheRightAnswerIs();
controller.getTheMainView().showCorrectAnswer(index);
}