title: How to draw a rectangle moving in a circle around the center of the canvas?
body: <p>The code is meant to draw a rectangle, which moves in a circle around the center of the canvas one time. The code I currently have is </p>
  
  <pre><code>import java.awt.Graphics;
  import java.awt.Graphics2D;
  import java.awt.event.ActionEvent;
  import java.awt.event.ActionListener;
  import java.awt.geom.Rectangle2D;
  import javax.swing.Timer;
  import javax.swing.JComponent;
  import javax.swing.JFrame;
  
  public class Q3_Circular extends JComponent {
  
  protected int degree = 0;
  protected double xStart;
  protected double yStart;
  protected Timer timer;
  
  
  public Q3_Circular() {
      timer = new Timer(1000, new TimerCallback()); //creates new times that refreshes every 100 ms, and called the TimerCallback class
      timer.start();
  }
  
  protected class TimerCallback implements ActionListener {
  
      public void actionPerformed(ActionEvent e) {
  
          if (degree &lt; (2 * Math.PI)){
              xStart = getWidth()/2 * Math.cos(degree+1);
              yStart = getHeight()/2 * Math.sin(degree+1);
              degree+= 1;
              repaint();
          }
          else {
              degree += 0;
              repaint();
          }
  
      }
  }
  
  
  public static void main(String[] args) {
      JFrame frame = new JFrame("AnimatedSquare");
      Q3_Circular canvas = new Q3_Circular();
      frame.add(canvas);
      frame.setSize(300, 300);
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);       
      frame.setVisible(true);
  }   
  
  public void paintComponent(Graphics g){
      xStart = (double)(getWidth())/2.0 * Math.cos(degree);
      yStart = (double)(getHeight())/2.0 * Math.sin(degree);
  
      Graphics2D g2 = (Graphics2D) g;
      g2.draw(new Rectangle2D.Double(xStart,yStart, 25,25));
      repaint();
  }
  }
  </code></pre>
  
  <p>This code appears to draw the rectangle very quickly around the point (0,0). I'm not sure where the code is wrong.</p>