QUOTE(gl3thr0 @ 4 Jun, 2008 - 11:09 AM)

Sorry gl3thr0 NOT a good idea at ALL to Thread.sleep() in an actionPerformed() method or any other AWT event
method that can really screw up any GUI
Your idea is not good at all....
Don't really know the details behind but imagine paint() is called in the same Thread. Your repaint() won't be executed until the Thread ends of its sleep
yes your right of course when the button is clicked it will look like its still pushed-in until the loop is finished.
i posted the code knowing this but hoping that mogstronaut would take both of our code and put it together.
if i did it id probably create an inner class that extended (Thread) and then override the run() method with the logic from my code BUT OH WELL
This is the code from my inner class im just using simple print statments to demonstrate the concept
java
public class Cycle extends Thread{ //this would be the inner class of TrafficLight
public void run(){
for(int i=0, x=2,y=1;i<3;i++,x++,y++){ //just like before to move through the array
if(x>2){
x=0;
}
if(y>2){
y=0;
}
System.out.println("i ="+i); //this is were u would turn lights on or off.
System.out.println("x ="+x);
System.out.println("y= "+y);
try {
this.sleep(1000);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
}
}
}
}
then from the actionPerformed() method you would do the same tht pbl did
Cycle c = new Cylce(); ----create the thread
c.start(); ----- start the thread
This post has been edited by gl3thr0: 5 Jun, 2008 - 07:52 AM