I've tried to change to yellow, then pause for 4 seconds before changing to green but it doesn't work.
public TrafficLight()
{
// Construct the circles
red = new Circle();
yellow = new Circle();
green = new Circle();
// Set their color and make them visible
red.changeColor("red");
red.makeVisible();
red.moveHorizontal(200);
red.moveVertical(200);
yellow.changeColor("black");
yellow.makeVisible();
yellow.moveHorizontal(200);
yellow.moveVertical(250);
green.changeColor("black");
green.makeVisible();
green.moveHorizontal(200);
green.moveVertical(300);
// Set stop to be true;
stop = true;
}
public void change() {
TrafficLight t1 = new TrafficLight();
if (stop = true) {
green.changeColor("green");
}
else {
yellow.changeColor("yellow");
}
}
This is where i'm having the problem.
Also, this is the code for making the yellow light pause for 4 seconds but it's not working.
private void pause() {
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
}
}
}