import java.awt.Color; /** * This class keeps track of the color of the traffic light */ public class TrafficLightModel { // The color of the traffic light private Color color; // The view associated to this model private TrafficLightView view; /** * Initialize the model (initially the traffic light is green) */ public TrafficLightModel(TrafficLightView view) { this.view = view; this.color = Color.green; // Tell the view that the model is ready this.view.updateDisplay(this); } /** * Change the color to green */ public void turnGreen() { this.color = Color.green; // Tell the view that the model has changed this.view.updateDisplay(this); } /** * Change the color to red */ public void turnRed() { this.color = Color.red; // Tell the view that the model has changed this.view.updateDisplay(this); } /** * Change the color to yellow */ public void turnYellow() { this.color = Color.yellow; // Tell the view that the model has changed this.view.updateDisplay(this); } /** * Switch to the next color (in the order green,yellow,red) */ public void nextColor() { } /** * Return the current color of the light */ public Color getColor() { return this.color; } }