title: Painting inside Swing Timer not working
body: <p>I never worked with <code>Timer</code>s before so my problem is probably stupid one really. My program draws a circle which is red and after random seconds the circle should change its color to green. I just made a swing timer as you can see below in the code. And it enters <code>actionPerformed()</code> method but it doesn't change color. Could you help me somehow fix my problem with changing colors?</p>
  
  <p>My code:</p>
  
  <pre><code>package igrica;
  import java.awt.BorderLayout;
  import java.awt.Color;
  import java.awt.Graphics;
  import java.awt.event.ActionEvent;
  import java.awt.event.ActionListener;
  import java.util.Random;
  
  import javax.swing.JButton;
  import javax.swing.JFrame;
  import javax.swing.JPanel;
  import javax.swing.Timer;
  
  
  public class ChangingCircle implements ActionListener{
  
  JFrame frame;
  
  Timer timer;
  Random r;
  
  public static void main(String[] args) {
      ChangingCircle gui = new ChangingCircle();
      gui.go();
  }
  
  public void go() {
      frame = new JFrame();
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  
      MyPanel panel = new MyPanel();
  
      frame.getContentPane().add(BorderLayout.CENTER, panel);
      frame.setSize(300, 300);
      frame.setVisible(true);
  }   
  
  public void actionPerformed(ActionEvent event) {
      frame.repaint();
  }
  
  class MyPanel extends JPanel {
      public void paintComponent(Graphics g) {
  
  
          g.setColor(Color.red);
          g.fillOval(100, 100, 100, 100);
  
          Random r = new Random();
  
          Timer timer = new Timer(r.nextInt(5000) + 1000, new ActionListener() {
              public void actionPerformed(ActionEvent ev) {
                  System.out.println("Timer out");
                  g.setColor(Color.green);
                  g.fillOval(100, 100, 100, 100);
              } 
          });
          timer.start();
      }
  }
  }
  </code></pre>