emaellie 0 Newbie Poster
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

class work
{
    // main method constructs the Frame window
        public static void main ( String[] args )
        {
        CircleWindow application = new CircleWindow();

        }// end of main method  
}// end of Line app

class CircleWindow extends Frame    
{
        private int nSeconds = 0;
        CircleWindow()
        {
        application.setTitle( "Traffic Lights");
        application.setLocation( new Point( 150,150 ));              //sets the positons of the traffic lights on the left side of the window
        application.setSize( 300,400 );                             //sets the size of the window
        application.setFont( new Font( "Arial", Font.BOLD,24 ));   //sets the font type, style and size in wondow.
        application.setBackground( Color.black);
        application.setVisible( true );
        application.addWindowListener( new WindowCatcher());

        Timer timer = new Timer( 1000, new TimerCatcher());
        }

    public void paint( Graphics gc )
    {
            if (Color == GREEN)
                gc.setColor( Color.GREEN ); 
                    else setBackground( Color.black);
                        gc.fillOval( 15, 300, 80, 80);

            if (Color == YELLOW)
                gc.setColor( Color.ORANGE );    
                    else setBackground( Color.black);
                        gc.fillOval( 15, 200, 80, 80);
            if (Color == RED) 
                gc.setColor( Color.RED );
                    else 
                        gc.fillOval( 15, 100, 80, 80);

        gc.setColor( Color.BLACK );
            gc.drawString( "" + nSeconds,100, 100 );
    }                                       //end of paint method


    class WindowCatcher extends WindowAdapter  
    {
        public void windowClosing( WindowEvent evt )
        {
        (evt.getWindow()).dispose();     // release the windows resource
        System.exit( 0 );               //application termination
        }
    }
    class TimerCatcher implements ActionListener
    {
        public void actionPerformed( ActionEvent evt)
        {
            nSeconds++;
            show circle();
        }
    }
}                                           //end of CircleWindow   

Hello programmer, i hope ur all alright...am new to Java doing this TrafficLight work and i Have managed to code everything but i got 1 error and i dont know what to do as i have tried everything. please feel free to correct the code where i have gone wrong. the Traffic lights need to be ON one by one, as one traffic light showing, the others need to be set to black so they dont show.
Thank You in advance....

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.