/* * TrafficLight.java * * Created on May 9, 2008, 2:05 PM */ package jlsim; import javax.swing.colorchooser.*; import java.awt.*; import java.awt.geom.*; import java.awt.event.*; import javax.swing.*; import java.lang.*; import java.util.*; /** * * @author jliu2 */ public class TrafficLight extends java.lang.Object { /** Creates a new instance of TrafficLight */ private int xlocation; private int ylocation; private Color startingcolor; private Color currentcolor; private int count=0; private double lengthgreen; private double lengthyellow; private double lengthred; private boolean operational; public TrafficLight() { startingcolor = Color.BLACK; operational = false; } public TrafficLight(int xpos, int ypos, Color currcolor, double lengreen ,double lenyellow, double lenred, boolean running) { xlocation=xpos; ylocation=ypos; startingcolor=Color.BLACK; currentcolor=currcolor; lengthgreen=lengreen; lengthyellow=lenyellow; lengthred=lenred; operational=running; } //access methods public int getLightXPos() { return this.xlocation; } public int getLightYPos() { return this.ylocation; } public Color getLightColor() { if(operational==true) { return this.currentcolor; } return this.startingcolor; } public double getLengthGreen() { return this.lengthgreen; } public double getLengthRed() { return this.lengthred; } public double getLengthYellow() { return this.lengthyellow; } public int getLightCount() { return this.count; } public boolean isOperational() { return this.operational; } //set methods public void setLightXPos(int xpos) { this.xlocation= xpos; } public void setLightYPos(int ypos) { this.ylocation=ypos; } public void setLightColor(Color c) { this.currentcolor=c; } public void setLengthGreen(double green) { this.lengthgreen=green; } public void setLengthRed(double red) { this.lengthred=red; } public void setLengthYellow(double yellow) { this.lengthyellow=yellow; } public void setOperational(boolean o) { this.operational=o; } public void increment() { this.count++; } public void reset() { this.count=0; } }