title: Rotate a graphic by user input (animation)
body: <p>I'm trying to write a program that simulates forces and I'm stuck on a section where I need to rotate the graphic by the angle the user inputs.</p>
  
  <p>Here the code for the graphic so far. </p>
  
  <pre><code>private class MomentsAnimation extends JPanel {
  
      int width = 440;
      int height = 300;
  
      int rotationAngle = 60;
  
      public MomentsAnimation() {
          setSize(width, height);
          setMaximumSize(new Dimension(width, height));
          setMinimumSize(new Dimension(width, height));
          setPreferredSize(new Dimension(width, height));
  
      }
  
      @Override
      public void paint(Graphics g) {
  
          int xcentre = width / 2;
          int ycentre = height / 2;
  
          g.setColor(Color.lightGray);
          g.drawRect(0, 0, width - 1, height - 1);
  
          g.setColor(Color.BLACK);
          g.fillOval(xcentre - 5, ycentre - 5, 10, 10); // draw the point of rotation, does not move in the animation
  
          g.setColor(Color.red);
          g.fillArc(xcentre - 150, ycentre - 50, 100, 100, 0, 45);
  
          g.setColor(Color.blue);
          g.drawLine(xcentre - 100, ycentre, xcentre, ycentre - 100); // draws the diagonal force line 
  
          g.setColor(Color.black);
          g.drawLine(xcentre - 100, ycentre, xcentre, ycentre); // draws horizontal line of distance from point of rotation
  
          g.drawString("θ", xcentre - 70, ycentre - 10);
  
      }
  
  
  }
  </code></pre>
  
  <p>Thanks</p>