Next steps?
I'm creating a Traffic Light Simulator just for the hell of it.
Modelled after a traffic light with 4 panels, N, S, E, W each with 4
lights R, G, FG, A (red, green, flashing green, amber) I'm using a
double dimensioned array [5][4] of an enum called State. Every 2
minutes, my program will "switch" the lights to the next in the
sequence. I won't bore you with the details but what I'm wondering
is, where should I go next? I want to now represent my traffic light
graphically. I want to have a panel with 4 sub panels
package TrafficLightSimulator.sim;
import TrafficLightSimulator.com.*;
public class TrafficLightTester {
public static void main(String [] args) {
final int twoMinutes=120000;
Light north = new Light(State.GO);
Light south = new Light(State.GO);
Light east = new Light(State.STOP);
Light west = new Light(State.STOP);
State[][] stateArray = {{State.GO, State.GO, State.STOP,
State.STOP},
{State.AMBER, State.AMBER, State.STOP, State.STOP},
{State.STOP, State.STOP, State.LEFT, State.LEFT},
{State.STOP, State.STOP, State.GO, State.GO},
{State.STOP, State.STOP, State.AMBER, State.AMBER},
{State.LEFT, State.LEFT, State.STOP, State.STOP}};
int count = 1;
while (count < 6 ) {
Thread t = new Thread();
t.start();
try {
Thread.sleep(twoMinutes);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if ( north.getLightState() != stateArray[count][0])
System.out.println("Switching north from " +
north.getLightState() + " to " + stateArray[count][0]);
north.setLightState(stateArray[count][0]);
if ( south.getLightState() != stateArray[count][1])
System.out.println("Switching south from " +
south.getLightState() + " to " + stateArray[count][1]);
south.setLightState(stateArray[count][1]);
if ( east.getLightState() != stateArray[count][2])
System.out.println("Switching east from " +
east.getLightState() + " to " + stateArray[count][2]);
east.setLightState(stateArray[count][2]);
if ( west.getLightState() != stateArray[count][3])
System.out.println("Switching west from " +
west.getLightState() + " to " + stateArray[count][3]);
west.setLightState(stateArray[count][3]);
count++;
if ( count == 6) count=0;
}
}
}
While there are probably many ways to clean this code up, I'm not
worried about cleaning it up. I will eventually move all the stuff
inside the loop to another method so that it stays oo'ed. What I'd
like to do is have the setLightState method trigger the change in the
color of the individual nodes.
Assuming I know absolutly nothing about graphics, what should I be
studying next to learn how to do this. I don't expect to be able to
code this "interface" right away, but I would like to eventually have
something that works. I chose the traffic light because it seemed to
be something in real life that I could model without running into the
nooks and crannies that other stuff like the Animal Kingdom would
cause. What portions of the SJT would be of the most help to me.