title: Fill objects with random color
body: <p>I have a code that has a button. When a button is pressed, circles appear at random positions with random colors. There can only be 10 circles. </p>
  
  <p>Now that I added random colors functionality, the problem is that after each circle is drawn, its color starts changing infinetely. </p>
  
  <p>How can I make it so the colors don't change? </p>
  
  <pre><code>class Panel extends JPanel  {
  
      private JButton button;
      private Ellipse2D.Double[] circles;
      Integer count;
  
  
      public Panel()  {
              setup();
      }
  
      private void setup()  {
              count=new Integer(0);
              circles=new Ellipse2D.Double[10];
              button=new JButton(count.toString());
              button.addActionListener(new ActionListener() {
                 @Override
                 public void actionPerformed(ActionEvent e) {
                              Random r=new Random();
                              //position circles with diameter 100 in a way 
                              //that it would fit in a window's size
                              int highX=getWidth()-100;
                              int highY=getHeight()-100;
                              circles[count]=new 
                                       Ellipse2D.Double(r.nextInt(highX), 
                                            r.nextInt(highY), 100, 100);
                              count++;
  
                              button.setText(count.toString());
                      }
                  });
  
            add(button);
          }
  
  
      public void paintComponent(Graphics g)  {
              super.paintComponent(g);
              paintStuff(g);
              repaint(); 
          }
  
      private void paintStuff(Graphics g)  {
              Graphics2D g2=(Graphics2D) g;
              g2.setPaint(Color.RED);
  
              if (count!=0)  {
                  for (int i=0; i&lt;count; i++)  {
                          g2.draw(circles[i]);
                          Random r=new Random();
                          int red=r.nextInt(256);
                          int green=r.nextInt(256);
                          int blue=r.nextInt(256);
                          g2.setPaint(new Color(red, green, blue));
                          g2.fill(circles[i]);
                  }
              }
      }
  }
  
  public class Frame extends JFrame  {
       private Panel panel;
       public Frame()  {
          panel=new Panel();
          add(panel);
       }
  
       public static void main(String[] args)  {
            Frame frame=new Frame();
       }
  }
  </code></pre>