title: Use different colors in same graphics (Java)
body: <p>I'm relatively new to Java.</p>
  
  <p>I need to do an exercise which draws different random shapes, with different positions and colors. I want every shape to have a different color. This is a part of my code (which has two different shapes, an oval and a rectangle). Now the two shapes have the same random color:</p>
  
  <pre><code>protected void paintComponent(Graphics g) {
    int R = (int)(Math.random()*256);
    int G = (int)(Math.random()*256);
    int B = (int)(Math.random()*256);
    Color color = new Color(R, G, B); // picks a random color
    int ovalA = (int)(Math.random()*400);
    int ovalB = (int)(Math.random()*300);
    int ovalC = (int)(Math.random()*(400 - ovalA));
    int ovalD = (int)(Math.random()*(300 - ovalB));
    int rectA = (int)(Math.random()*300);
    int rectB = (int)(Math.random()*400);
    int rectC = (int)(Math.random()*(400 - rectA));
    int rectD = (int)(Math.random()*(300 - rectB));
    super.paintComponent(g);
    g.setColor(color);
    g.fillOval(ovalA, ovalB, ovalC, ovalD);
    g.fillRect(rectA, rectB, rectC, rectD);
  </code></pre>
  
  <p>}</p>