public void actionPerformed(ActionEvent ae){
  long currentTime=System.nanoTime() / 1000000;
  long totalTime=currentTime - animStartTime;
  if (totalTime > animationDuration) {
    animStartTime=currentTime;
  }
  float fraction=(float)totalTime / animationDuration;
  fraction=Math.min(1.0f,fraction);
  int red=(int)(fraction * endColor.getRed() + (1 - fraction) * startColor.getRed());
  int green=(int)(fraction * endColor.getGreen() + (1 - fraction) * startColor.getGreen());
  int blue=(int)(fraction * endColor.getBlue() + (1 - fraction) * startColor.getBlue());
  currentColor=new Color(red,green,blue);
  repaint();
}

public void actionPerformed ( ActionEvent ae ) { long currentTime = System . nanoTime ( ) / 1000000 ; long totalTime = currentTime - animStartTime ; if ( totalTime > animationDuration ) { animStartTime = currentTime ; } float fraction = ( float ) totalTime / animationDuration ; fraction = Math . min ( 1.0f , fraction ) ; int red = ( int ) ( fraction * endColor . getRed ( ) + ( 1 - fraction ) * startColor . getRed ( ) ) ; int green = ( int ) ( fraction * endColor . getGreen ( ) + ( 1 - fraction ) * startColor . getGreen ( ) ) ; int blue = ( int ) ( fraction * endColor . getBlue ( ) + ( 1 - fraction ) * startColor . getBlue ( ) ) ; currentColor = new Color ( red , green , blue ) ; repaint ( ) ; }
callback from the swing timer . calculate the fraction elapsed of our desired animation duration and interpolate between our start and end colors accordingly .
