title: how do i stop repeat calls to java paint() replacing the last one?
body: <p>I create a window with a panel with custom panel class  and paint circles on it based on array data. How do I get both sets of circles to stay on screen?</p>
  
  <pre><code>import java.awt.Color;
  import java.awt.*;
  import javax.swing.*;
  
  class DataPaint extends JPanel {
      static int offsetY = 0;
      int leftX = 20;
      int[] guessColours;
      Color purple = new Color(155, 10, 255);
      Color pink = new Color(255, 125, 255);
      Color[] Colours = { Color.blue, Color.cyan, Color.green, Color.orange,
              pink, purple, Color.red, Color.yellow };
  
      public DataPaint() {
          setBackground(Color.WHITE);
      }
  
      public void paintClues(int[] guessColours) {
          this.guessColours = guessColours;
          offsetY += 30;
      }
  
      // naive attempt to make it work !!!!
      // what is diff between paintComponent and paint?
      public void update(Graphics g) {
          paintComponent(g);
      }
  
      // paint circles based on array data
      public void paintComponent(Graphics g) {
          super.paintComponent(g);
  
          Graphics2D g2 = (Graphics2D) g;
  
          for (int i = 0; i &lt; guessColours.length; i++) {
              g2.setPaint(Colours[guessColours[i]]);
              g2.fillOval(leftX + (i * 30), offsetY, 20, 20);
          }
      }
  
      // create window with panel and paint circles on it based on array data
      public static void main(String args[]) {
          JFrame frame = new JFrame("data paint");
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.setSize(300, 300);
  
          DataPaint panel = new DataPaint();
          frame.add(panel);
          frame.setVisible(true);
  
          int[] cols = { 2, 4, 5, 3, 6 };
          int[] cols2 = { 1, 3, 7, 3, 4 };
          // the second call replaces the first call on the panel?
          panel.paintClues(cols);
          panel.paintClues(cols2);
  
      }
  }
  </code></pre>