title: Trying to animate a die roll in Java
body: <p>I'm attempting to "animate" a die roll in Java.  I currently have an icon (called "diceImage") set up that, when a button is clicked (called "diceRoll"), updates to a new random image of a die face.  What I would like to do is have it change image (to a random die face) numerous times over a couple of seconds before stopping on a final image.</p>
  
  <p>The problem I have is not with generating a random number, or rolling it numerous times, it's with the updating the image numerous times within a loop.  The code below, which rolls the die 10 times is what I have so far:</p>
  
  <pre><code>private void diceRollActionPerformed(java.awt.event.ActionEvent evt) {                                         
  
      for (int i = 1; i &lt;= 10; i++) {
          rollDice();
          pause(100);
      }
  }   
  </code></pre>
  
  <p>This links to the following two methods (the first of which generates the random number, and sets the icon image):</p>
  
  <pre><code>private void rollDice() {
  
      Random r = new Random();
      int randomNumber = r.nextInt(6) + 1;
  
      diceImage.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Game/Images/Dice " + randomNumber + ".png")));
  
  }
  </code></pre>
  
  <p>The method below is "supposed" to pause the programme briefly between updating the image (this was taken from a programming course I was on where we had to animate an image of a car moving across the screen):</p>
  
  <pre><code>private void pause(int sleepTime) {
      try {
          Thread.sleep(sleepTime);
      } catch (InterruptedException e) {
          System.exit(-1);
      }
  }
  </code></pre>
  
  <p>All this programme seems to do is pause and then print the final dice roll.  It doesn't show any of the "intermediate" faces.  Does anyone have any ideas on why this isn't working?</p>
  
  <p>Any help is greatly appreciated.</p>