title: Java graphics trouble
body: <p>I have a JComponent with a listener on it. On the JComponent, I draw a big image and the mouse listener adds small images where clicks occur (one big map on which I add some dots).</p>
  
  <p>How can I programatically draw something outside the paintComponent method?</p>
  
  <pre><code> public void paintComponent(Graphics g) {
     Graphics2D g2 = (Graphics2D) g;
  
     g2.drawImage(img1, 0, 0, this);
     g2.finalize();
  
   }
  
   private MouseListener listener; 
  
   public void initListener() {
     myCanvas = this;
     listener = new MouseAdapter() {
       public void mouseClicked(MouseEvent e) {
         myCanvas.getGraphics().drawImage(img,e.getX(),e.getY(), myCanvas);
       }
     };
     addMouseListener(listener);
  
   }
  </code></pre>
  
  <p>My problem is with this:</p>
  
  <pre><code>public void drawDot(int x, int y){
   myCanvas.getGraphics().drawImage(img, x, y, myCanvas);
  }
  </code></pre>
  
  <p>It doesn't do anything. I have tried repaint().</p>