title: Change the color of an oval at click in Java AWT
body: <p>I have to draw some ovals in Java, and at click to change their color.
  For the beginning I tried to change the color after 20 ms, but it doesn't work.</p>
  
  <p>My code is:</p>
  
  <pre><code>public class MyComponentNew extends Frame {
  
      public Graphics2D g2d;
  
      public MyComponentNew(String title) {
          super(title);
          setSize(400, 550);
      }
  
      @Override
      public void paint(Graphics g) {
          this.g2d = (Graphics2D) g;
  
          this.g2d.setColor(Color.red);
          this.g2d.fillOval(10, 55, 50, 100);
      }
  
      public void changeColor () {        
          this.g2d.setColor(Color.blue);
          this.g2d.fillOval(10, 55, 50, 100);
      }
  }
  </code></pre>
  
  <p>And in the class with main method I have:</p>
  
  <pre><code>MyComponentNew m;
  
  m = new MyComponentNew("Fereastra cu baloane");
  m.setVisible(true);
  
  m.addWindowListener(new WindowAdapter() {
      @Override
      public void windowClosing(WindowEvent we) {
          System.exit(0);
      }
  });
  
  try {
      Thread.sleep(20);
  } catch(InterruptedException e) {} 
  
  m.changeColor();
  </code></pre>
  
  <p>The color of the oval remains red.</p>