title: Update a draw in a Java Canvas
body: <p>I want to make an application in which I can draw a path on a canvas. The problem is that I have to update this canvas continuously.</p>
  
  <p>Currently I'm able to do it, but I have to redraw all the path every time and so I have to store all the points in memory. I would prefer to simply update the draw by adding a new point.</p>
  
  <p>Is it possible?</p>
  
  <p>Currently my code is:</p>
  
  <pre><code>public class MyCanvas extends Canvas{
          private static final long serialVersionUID = 1L;
          public MyCanvas(){}
          public void paint(Graphics graphics){
              super.paint(graphics);
              graphics.setColor(Color.green);
              // points is an ArrayList of Point2D
              for (Iterator iterator = points.iterator(); iterator.hasNext();) {
                 Point2D point2d = (Point2D) iterator.next();
                 graphics.fillOval((int)((canvas.getWidth()/2.0) + point2d.getX()), (int)((canvas.getHeight()/2.0) + point2d.getY()), 5, 5);
              }   
          }
      }
  </code></pre>
  
  <p>Thanks!</p>
  
  <p>EDIT</p>
  
  <p>This is the current solution:</p>
  
  <pre><code>PanelCanvas canvasPanel;
  ...
  public void drawCircle(int x, int y){
      Graphics2D g2d = bufferedImage.createGraphics();
      g2d.setColor(Color.green);
      g2d.setBackground(Color.white);
      g2d.fillOval((int)((panelCanvas.getWidth() / 2.0) + x/10.0), (int)((panelCanvas.getHeight() / 2.0) + y/10.0), 5, 5);
      panelCanvas.repaint();
  }
  
  public class CanvasPanel extends JPanel{
      public void paintComponent(Graphics graphics){
          super.paintComponents(graphics);
          Graphics2D g2d = (Graphics2D)graphics;
          g2d.setBackground(Color.white);
          g2d.drawImage(bufferedImage, null, 0, 0);
      }
  }
  </code></pre>