title: Program freezes during Thread.sleep() and with Timer
body: <p>Original question:</p>
  
  <p>This method is supposed to change the image being displayed on a JFrame gradually into another image. However, without some way to slow it down, it just seems to change from one image to the new image. In order to slow it down, I put in a Thread.sleep(1000) so the changes wouldn't happen instantly. However, with this line in there, my program freezes completely. No error message, no nothing. Can anyone please help me out? Suggest a better method to slow it down, or how this can be fixed.</p>
  
  <p>For clarification: int k is the number of gradual steps in the change. k = 1 would be an instant change. Anything greater would be gradual changes. int l meanwhile controls the ratio of how much of each image is displayed.</p>
  
  <pre><code>public void morphImg(int width, int height, BufferedImage morphImage, int k) {
      //creates new image from two images of same size
      BufferedImage image2 = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
      for (int i = 0; i &lt; width; i++) {
          for (int j = 0; j &lt; height; j++) {
              //get color from original image
              Color c = new Color(image.getRGB(i, j));
  
              //get colors from morph image
              Color c2 = new Color(morphImage.getRGB(i, j));
  
              for (int l = 1; l &lt;= k; l++) {
                  //gets colors at different stages
                  int r = ((k-l)*c.getRed()/k) + (l*c2.getRed()/k);
                  int g = ((k-l)*c.getGreen()/k) + (l*c2.getGreen()/k);
                  int b = ((k-l)*c.getBlue()/k) + (l*c2.getBlue()/k);   
                  Color newColor = new Color(r, g, b);
                  //set colors of new image to average of the two images
                  image2.setRGB(i, j, newColor.getRGB());
  
                  //display new image
                  try {
                      imageLabel.setIcon(new ImageIcon(image2));
                      Thread.sleep(1000);
                  }
                  catch (InterruptedException e){
                      System.out.println("Exception caught.");
                  }
              }
          }
      }
  
      //sets modified image as "original" for further manipulation
      setImage(image2);
  }
  </code></pre>
  
  <p>UPDATED CODE: Using a Timer also causes the program to freeze...Am I not using it right?</p>
  
  <pre><code>public void morphImg(int width, int height, BufferedImage morphImage, int k) {
      //creates new image from two images of same size
      final BufferedImage image2 = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
      for (int l = 1; l &lt;= k; l++) {
          for (int i = 0; i &lt; width; i++) {
              for (int j = 0; j &lt; height; j++) {
                  //get color from original image
                  Color c = new Color(image.getRGB(i, j));
  
                  //get colors from morph image
                  Color c2 = new Color(morphImage.getRGB(i, j));
  
                  //gets colors at different stages
                  int r = ((k-l)*c.getRed()/k) + (l*c2.getRed()/k);
                  int g = ((k-l)*c.getGreen()/k) + (l*c2.getGreen()/k);
                  int b = ((k-l)*c.getBlue()/k) + (l*c2.getBlue()/k);   
                  Color newColor = new Color(r, g, b);
  
                  //set colors of new image to average of the two images
                  image2.setRGB(i, j, newColor.getRGB());
                  //display new image
  
                  imageLabel.setIcon(new ImageIcon(image2));
                  final Timer t = new Timer(500,null);
                  t.setInitialDelay(500);
                  t.start();
              }
          }
      }
  
      //sets modified image as "original" for further manipulation
      setImage(image2);
  }
  </code></pre>