Create a Java applet that will draw three circles similar to those on a traffic light. Their colors should be red, yellow (orange actually looks better) and green. Position them on the applet in the order that they would be for a traffic light. Run the applet from an html file like the one below.
<HTML>
<HEAD>
<TITLE>Lights</TITLE>
</HEAD>
<BODY>
<H1>Lights</H1>
<APPLET
CODE="Lights.class" WIDTH=300 HEIGHT=300></APPLET>
</BODY>
</HTML>
Your applet should have the following form:
// An applet with a class that draws a few circles that
look like a traffic light. import java.awt.*; import java.applet.Applet;
public class Lights extends Applet
{
private circle redCircle, yellowCircle,
greenCircle;
public void init ()
{
redCircle =
new circle ();
yellowCircle
= new circle ();
greenCircle
= new circle ();
} // method init
public void paint (Graphics g)
{
// Fill in
the statements here that would draw the circles.
} // method paint
} // class shapes
// A class that defines a circle.
class circle
{
public void displayCircle (Graphics
g, Color c, int xPos, int yPos, int diameter)
{
// Fill in
the statements here that would set the color and draw the circle.
} // method displayCircle
} // class circle