title: How to set the gradient of a shape when the JFrame is constantly being repainted?
body: <p>I'm trying to get an oval to change its gradient's colours every time it reaches a size of 50 or 100: </p>
  
  <pre><code>    class MyDrawPanel extends JPanel {
      public void paintComponent(Graphics g) {
  
          Graphics2D g2d = (Graphics2D) g;
  
          g2d.setColor(Color.white);
          g2d.fillRect(0, 0, 300, 300);
  
          if(dmt == 100 || dmt == 50) {
              int red = (int) (Math.random() * 256);
              int blue = (int) (Math.random() * 256);
              int green = (int) (Math.random() * 256);
              Color startColour = new Color(red, green, blue);
  
              red = (int) (Math.random() * 256);
              blue = (int) (Math.random() * 256);
              green = (int) (Math.random() * 256);
              Color endColour = new Color(red, green, blue);
  
              GradientPaint gradient = new GradientPaint(300, 100, startColour, 150, 150, endColour);
              g2d.setPaint(gradient);
          }
          g2d.fillOval((size-dmt)/2, (size-dmt)/2 - dmt/2, dmt, dmt);
      }
  }
  </code></pre>
  
  <p>(dmt is diameter, size is size of window that comes up)</p>
  
  <p>I set 2 random colours for the gradients I want to use for a circle, but I want it to change only when the circle reaches either size 100 or 50 (it is constantly growing and shrinking to these sizes), but since I repaint everything white every time it runs, you can never see it except when its size is exactly 50 or 100. How do I make it always that colour, until it has to change?</p>