title: Why is paintComponent() getting called multiple times?
body: <p>Im trying to write a class implementing the observer interface, this class draws rectangles vertically according to the inputs from the textField. Everything run normally except my rectangles did not start from coord(0, 0). I tried to put a System.out.print and see what is going on, and it seems like my paintComponent() is called twice. I couldn't figure out where went wrong exactly. Can anyone please help me solve this problem? Below is my code:</p>
  
  <pre><code>public void paintComponent(Graphics g)
      {
          super.paintComponent(g);
          Graphics2D g2 = (Graphics2D)g;
          for (int i = 0; i &lt; dm.getData().size(); i++)
          {
              Rectangle2D rectangle = new Rectangle2D.Double(x, y, dm.getDataElement(i), height);
              g2.draw(rectangle);
              System.out.println(i + "th rec drew.");
              y = y + height;
          }
      }
  
  public void update(Observable o, Object arg) {
          // TODO Auto-generated method stub
          repaint();
      }
  </code></pre>