I'm trying to display 2 images on user mouse click. The first image should be displayed, then a pause occurs, and then the second image displays.
Ultimately I want both images to display one right after the other for the duration of the program's execution.
I'm trying to use a while loop to first display image1, sleep, display image2, and then loop back to the beginning of the loop.
What ends up happening on mouse click is that the loop iterates 4 times with a 1 second delay on each iteration and after the loop is done looping, the second image is displayed only once and the first image display line of code is completely ignored the entire time.
The expected output was:
Loop Start iteration 1: Display image1, sleep 1 second, Display image2 iteration 2: Display image1, sleep 1 second, Display image2 iteration 3: Display image1, sleep 1 second, Display image2 iteration 4: Display image1, sleep 1 second, Display image2 Loop End
What ends up happening is:
Loop Start iteration 1: sleep 1 second iteration 2: sleep 1 second iteration 3: sleep 1 second iteration 4: sleep 1 second Loop End Display image2
int x = 0;
while (x < 4) {
iView.setImage(image1);
try {
Thread.sleep(1000);
} catch (Exception e) {}
iView.setImage(image2);
x++;
}
Any help is greatly appreciated. Thank you