title: Java - simple animation of rotation
body: <p>I am beginner when it comes to java and I have come across with a problem that I haven't found a solution to just yet. The thing is that I have working methods for drawing an letter and also for rotating it - when I set rotation it works the way it should. However I would like to make this slightly more interactive, at school we were given the basic framework for that - I was able to create a button that when you click on it the letter's angle changes and the letter is redrawed correctly. But I would like to make it an animation, for example you click on the button and for 10 seconds (or until you press the button again) the letter will be rotating. </p>
  
  <p>On the internet I found a way to perform an action after certain period of time, and I thought I will use this. I wanted to add an angle and redraw an image, after let's say 1 second, then it would repeat - I thought this would make it look like it is animated. But I was wrong. I tried so many ways to do this, the best thing was that after few seconds that I set I want the animation to go for, it changed an angle and redraw, unfortunately it was the final state and it didn't draw states in between to create an animation. And this latest code doesn't even do that, the program just freezes.</p>
  
  <pre><code>int animation = 0;
  int steps = 0;
  
  public void G_draw() {
          graphic.clear();
          if (animace==1)
          {
              animation();
          }
  
          letter('a', G_Color.G_cBlack, 2, 2);//drawing an letter
  }
  
  public void G_mousePressed(G_Button button, int x, int y) {
      if (button.equals(G_Button.B_LEFT)&amp;&amp;x&gt;700&amp;&amp;x&lt;750&amp;&amp;y&gt;500&amp;&amp;y&lt;520){
              animation=1;
              G_draw();
          }
  }
  
  public void animation() {
          long start = System.currentTimeMillis();
          long end = start + 2 * 1000; 
          while (System.currentTimeMillis() &lt; end) {
  
          }
          langle+=30; // adding an angle
          steps++;
  
          G_repaint();
          G_draw();
          if (steps&lt;4) animace();
  }
  </code></pre>