Question: Task #1 Create an Applet TrafficApplet.java 2. This class currently has all the constants you will need to be able to create your traffic signal.

Task #1 Create an Applet

TrafficApplet.java

2. This class currently has all the constants you will need to be able to create your

traffic signal. It doesnt have anything else . You will need to change the class heading so that it extends JApplet.

Task #2 The Timer Object

1. An applet does not have a constructor or a main method. Instead, it has a method named init that performs the same operations as a constructor. The init method accepts no arguments and has a void return type.

Write an init method.

2. Inside the init method, create a Timer object passing in the TIME_DELAY constant and a new TimerListener

(We will be creating the listener class next).

3. Call the start method with the Timer object to generate action events.

Task #3 The TimerListener Class

1. Write a private inner class called TimerListener which implements ActionListener.

2. Inside this class, write an actionPerformed method. This method will check the status variable to see whether it is currently red, orange, or green. Since we want the lights to cycle as a traffic signal, we need to cycle in the order: green, orange, red, green, orange, red, and so on. Once the status is determined, the status should then be set to the next color in the cycle.

3. Redisplay the graphics components (to be created next) by calling the repaint method.

Task #4 Drawing Graphics

1. draw the traffic signal by overriding the paint method. For all graphics, use the named constants included in the class.

2. Call the method that is being overridden in the parent class.

3. Create a yellow rectangle (solid color) for the traffic signal. The constants X_TRAFFICLIGHT, Y_TRAFFICLIGHT,

TRAFFICLIGHT_WIDTH, and TRAFFICLIGHT_HEIGHT have already been defined for your use.

4. Create round lights of red, orange, and green for the signals. These should be

outlines of these colors. The constants X_LIGHTS, Y_REDLIGHT, Y_GREENLIGHT, Y_ORANGELIGHT, and

LIGHT_DIAMETER, have already been defined for your use. Only one light will be filled in at a time, when the

status indicates that one has been chosen. You will need to check the st determine which light to fill in. Remember, the status is changed only in the actionPerformed method (already defined) where the repaint method is also called.

5. Put the shade hoods above the lights by drawing black arcs above each light. The constants HOOD_START_ANGLE and HOOD_ANGLE_SWEPT have already been defined for your use.

6. Try out your applet. If time permits, create a web page on which you can display your applet

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!