title: Draw and redraw on a canvas in swing
body: <p>I know there's no direct replacement for <code>java.awt.Canvas</code> in swing, and I know <a href="https://stackoverflow.com/questions/776180/how-to-make-canvas-with-swing">I'm supposed to use a JPanel</a> and override <code>paintComponent</code>, for example like so:</p>
  
  <pre><code>public void paintComponent(Graphics g) {
      g.setColor(Color.black);
      g.drawOval(0, 0, 100, 100);
  }
  </code></pre>
  
  <p>And this would draw a black circle on the JPanel when it is created. The problem I have is that I want a dynamic canvas: I want to be able to draw things in response to user input, and redraw continuously, not just once when the application starts. An example would be having a moving object on a canvas, that would need to be redrawn at a rate of say 60 frames per second. How could I achieve this without using AWT components?</p>
  
  <p>EDIT: what I mean is, in an actual canvas, I'd be able to arbitrarily call, say, <code>drawOval</code> anywhere in my code, and that would draw an oval on the canvas; is this doable with JPanel?</p>