title: Java controls animation - how to make them smooth and efficient
body: <p>I am programming some custom controls in Java and using animation for transitions/fades/movements.</p>
  
  <p>The way I am doing this is that I am starting a new thread and making adjustments to variables and things are adjusted using <code>paint()</code> method.</p>
  
  <h2>Example:</h2>
  
  <p>Now, my question is, let's say for instance that I was implementing a fade in. What I would do is increment the alpha variable by <code>byte x    //between 0-255</code> and paint a rectangle where <code>alphaLevel += x</code>, for instance (in pseudo-code):</p>
  
  <pre><code>byte increment = 40;
  
  for (byte i = 0; i &lt; 255; i += increment)
  {
      _parentClass.setAlphaLevel (i);
      _parentClass.repaint();
      Thread.sleep (10);    
  }
  
  _parentClass.setAlphaLevel (255);
  </code></pre>
  
  <p>What I want to know is what is the lowest and what is the highest I should set the sleep to so that the animation doesn't look choppy? Does it have anything todo with the target device refresh rates or anything todo with the human eyes? Same question again with step. Is there a website that will give me good figures I can copy.</p>
  
  <p>The reason I ask, is to maximize efficiency as it is going to be run on a battery operated device so more CPU time = less battery. What would you set it to?</p>
  
  <p>Thanks.</p>