title: Draw circle on JPanel after mouse click
body: <p>I want to draw circle only after mouse gets click. As paintComponent method called itself, so first circle draw without click.</p>
  
  <pre><code>public class DrawPanel extends JPanel implements MouseListener {
  private static final long serialVersionUID = 1L;
  int x, y;
  
  public DrawPanel() {
      setBackground(Color.WHITE);
      addMouseListener(this);
  }
  
  public void paintComponent(Graphics g) {
      Graphics2D g2 = (Graphics2D) g;
      g2.setColor(Color.red);
      g2.fillOval(x, y, 20, 20);
  }
  
  @Override
  public void mouseClicked(MouseEvent e) {
      x = e.getX();
      y = e.getY();
      repaint();
  }
  
  }
  </code></pre>