Pause between images in Java

44 views Asked by At

I've created a GUI that goes to a new screen (JPanel) when a button is clicked. After this, I would like it to show ImageIcons from an array (1 every few seconds), replacing the old one with the new one. I have seen ways to "pause" the execution for a specified amount of seconds (Thread.sleep()), but this only seems to pause the amount of time between the button being clicked and going to the new screen, only displaying the last image.

I've tried this:

    for(int i = 0; i < array.length(); i++) {
        try{
            Thread.sleep(1000);
            g.drawImage(myImageArray[i]);
        } catch(Exception e) {
           System.out.println("Exception caught");
        }
    }

With no luck. Any suggestions?

0

There are 0 answers