title: How to update color of a Swing Oval
body: <p>I would like to dynamically update the color of a Swing Oval I have drawn in my java swing app. Can Someone please help me?</p>
  <p>my circle class I created to draw the ovals:</p>
  <pre><code>public static class Circle extends JPanel{
          int x;
          int y;
          int diameter;
          Color color;
          public Circle( int x, int y, int diameter, Color color ) {
              this.x = x;
              this.y = y;
              this.diameter = diameter;
              this.color = color;
          }
          @Override
          public void paintComponent( Graphics g ) {
              super.paintComponent( g );
              setSize( diameter + 1, diameter + 1 );
              g.setColor( color );
              g.fillOval( x, y, diameter, diameter );
              
        }
      }
  </code></pre>
  <p>Where I add the circle to my panel (status circle is an instance variable in my class):</p>
  <pre><code>statusCircle = new Circle( 0, 0, 15, getStatusColor(currentSimStatus) );
  statusCircle.setBackground( Color.DARK_GRAY );
  bottomPanel.add( statusCircle );
  </code></pre>
  <p>Where I want to update my circle, <strong>note</strong> the setCurrentSimStatus is called externally by another class which should in turn trigger the update. This is working as the statusText JLabel value does update as expected. I'm just unsure of how to update the circle:</p>
  <pre><code>public void setCurrentSimStatus( String newStatus) {
          currentSimStatus = newStatus;
          this.update();
      }
  
  private void update() {
          
          statusText.setText( &quot;Current Sim Status:&quot; + currentSimStatus );
          statusCircle = new Circle(0, 0, 15, getStatusColor(currentSimStatus) );
          statusCircle.updateUI();
          System.out.println(&quot;repainting&quot;);
      }
  </code></pre>