title: Change Object Color on scheduled time
body: <p>I am trying to simulate an intersection , so far i've painted my intersection . Now i want to make the traffic light. The problem is that i can't make my circle to change it's color from green to red every X seconds.
  Please help me.</p>
  
  <pre><code>import java.awt.Color;
  
  import javax.jws.Oneway;
  import javax.swing.JFrame;
  
  
  public class Main {
  
      public static void main(String[] args) {
          MyMap map = new MyMap();
          JFrame f = new JFrame("Broadway Intersection");
          f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          map.setBackground(Color.white);
          f.add(map);
          f.setSize(1366,738);
          f.setVisible(true);
      }
  
  }
  
  
  My Map class
  
  import java.awt.Color;
  import java.awt.Graphics;
  import java.util.Timer;
  import java.util.TimerTask;
  
  import javax.swing.JPanel;
  
  public class MyMap extends JPanel {
      public void paintComponent(final Graphics g) {
          super.paintComponent(g);
  
          g.setColor(Color.GREEN);
          g.fillRect(0, 0, 500, 250); // stanga sus
          g.fillRect(900, 0, 500, 250); // dreapta sus
          g.fillRect(0, 500, 500, 250);// stanga jos
          g.fillRect(900, 500, 500, 250); // dreapta jos
  
          g.setColor(Color.GRAY);
          g.fillRect(500, 0, 400, 900);
          g.fillRect(0, 250, 500, 250);
          g.fillRect(900, 250, 500, 250);
  
          g.setColor(Color.WHITE);
          g.fillRect(695, 0, 5, 100);// linii verticale
          g.fillRect(695, 150, 5, 100);
          g.fillRect(695, 500, 5, 100);
          g.fillRect(695, 650, 5, 50);
  
          g.fillRect(0, 370, 50, 5);
          g.fillRect(100, 370, 100, 5); // linii orizontale
          g.fillRect(250, 370, 100, 5);
          g.fillRect(400, 370, 100, 5);
          g.fillRect(900, 370, 100, 5);
          g.fillRect(1050, 370, 100, 5);
          g.fillRect(1200, 370, 100, 5);
  
          Timer timer = new Timer();
          boolean semaphore =true;
              timer.schedule(new TimerTask() {
                  @Override
                  public void run() {
  
                      g.setColor(Color.RED);
                      g.fillOval(700, 400, 20, 20);
                      System.out.println("tic tac");
                  }
              }, 0, 5000);
              g.setColor(Color.GREEN);
              g.fillOval(700, 400, 20, 20);
      }
  
  }
  </code></pre>
  
  <p>I have a circle in center that i want to change it's color , than i will start drawing my traffic light :D Thanks for everyone who is helping.</p>