hi , i have a program which i am stock in , its about traffic light . i did the display part but i cant do the timeing and changing the color of the traffic signal . if one signale is green there should be a timer which has time about 5sec and when the time finish the color will change to yellow for 2sec and then red then the turn well be for other traffic light and so on . how can i add the timing in that
here is what i did please help

import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import javax.swing.*;

public class LineApplet extends Applet
{
  public static final int IDEAL_WIDTH = 600;
  public static final int IDEAL_HEIGHT = 600;

  public void paint(Graphics g)
  {
    g.setColor(Color.lightGray);
    g.fillRect(0, 0, getWidth(), getHeight());
    g.setColor(Color.BLACK);


   g.drawLine( 250, 0, 250, 250);
   g.drawLine( 350, 0, 350, 250);
   g.drawLine( 250, 350, 250, 600);
   g.drawLine( 350, 350, 350, 600);
   g.drawLine( 0, 250, 250, 250);
   g.drawLine( 0, 350, 250, 350);
   g.drawLine( 350,250, 600, 250);
   g.drawLine( 350, 350, 600, 350);

   //CROSSING from top to botton

   g.setColor(Color.white);
   g.fillRect(300,5,2,50);
   g.drawRect(300,5,2,50);


    g.setColor(Color.white);
    g.fillRect(300,105,2,50);
    g.drawRect(300,105,2,50);

    g.setColor(Color.white);
    g.fillRect(300,200,2,50);
    g.drawRect(300,200,2,50);

    g.setColor(Color.white);
    g.fillRect(300,360,2,50);
    g.drawRect(300,360,2,50);   


    g.setColor(Color.white);
    g.fillRect(300,450,2,50);
    g.drawRect(300,450,2,50);

    g.setColor(Color.white);
    g.fillRect(300,550,2,50);
    g.drawRect(300,550,2,50);

    //cross from left to right

    g.setColor(Color.white);
    g.fillRect(0,300,50,2);
    g.drawRect(0,300,50,2);

    g.setColor(Color.white);
    g.fillRect(100,300,50,2);
    g.drawRect(100,300,50,2);

    g.setColor(Color.white);
    g.fillRect(190,300,50,2);
    g.drawRect(190,300,50,2);


    g.setColor(Color.white);
    g.fillRect(370,300,50,2);
    g.drawRect(370,300,50,2);


    g.setColor(Color.white);
    g.fillRect(470,300,50,2);
    g.drawRect(470,300,50,2);

    g.setColor(Color.white);
    g.fillRect(550,300,50,2);
    g.drawRect(550,300,50,2);

   //traffic light circle
    g.setColor (Color.red);
    g.fillOval (200,290,30,30);
    g.fillOval (170,290,30,30);
    g.fillOval (140,290,30,30);

    g.setColor (Color.red);
    g.fillOval (380,290,30,30);
    g.fillOval (410,290,30,30);
    g.fillOval (440,290,30,30);


    g.setColor (Color.red);
    g.fillOval (290,370,30,30);
    g.fillOval (290,400,30,30);
    g.fillOval (290,430,30,30);

    g.setColor (Color.red);
    g.fillOval (290,140,30,30);
    g.fillOval (290,170,30,30);
    g.fillOval (290,200,30,30);





  }  


  public static void main(String args[])
  {
    Applet applet = new LineApplet();
    Frame frame = new Frame();
    frame.addWindowListener(new WindowAdapter()
    {
      public void windowClosing(WindowEvent e)
      {
        System.exit(0);
      }
    });

    frame.add(applet);
    frame.setSize(IDEAL_WIDTH, IDEAL_HEIGHT);
    frame.show();


  }

}

try{
thread.sleep(time);
}catch (InterruptedException e){}

but i dont know how to put that . i need to make the lights start from one signal green yello red each having time . ho should i do so ,,

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.