import javax.swing.JFrame;
public class TrafficControlApp {
/** * @param args */ public static void main(String[] args) { TrafficLight application = new TrafficLight(); application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); }
}
import java.awt.Color; import java.awt.Font; import java.awt.Graphics;
public class TrafficFixtureForward{
public int locateX; public String direction; public TrafficFixtureForward(String direction, int locateX){ this.locateX = locateX; this.direction = direction; } public void trafficLight(Graphics g, int state){ g.setColor(Color.black); g.setFont(new Font("Arial",Font.BOLD, 12)); g.drawString(direction, (locateX+4), 250); switch(state){ case 1: g.setColor(Color.red); g.fillOval(locateX,30,50,50); g.setColor(Color.black); g.fillOval(locateX,90,50,50); g.setColor(Color.black); g.fillOval(locateX,150,50,50); break; case 2: g.setColor(Color.black); g.fillOval(locateX,30,50,50);
g.setColor(Color.yellow); g.fillOval(locateX,90,50,50);
g.setColor(Color.black); g.fillOval(locateX,150,50,50); break; case 3: g.setColor(Color.black); g.fillOval(locateX,30,50,50);
g.setColor(Color.black); g.fillOval(locateX,90,50,50);
g.setColor(Color.green); g.fillOval(locateX,150,50,50); break; case 4: g.setColor(Color.black);