Timer in Java swing
- by Yesha
I'm trying to replace Thread.sleep with a java swing timer as I hear that is much better for graphics.
Before, I had something set up like this, but it was interfering with the graphics.
while(counter < array.size){
Thread.sleep(array.get(counter).startTime);
//do first task
Thread.sleep(array.get(counter).secondTime);
//do second task
Thread.sleep(array.get(counter).thirdTime);
//do third task
counter++
}
Now, I'm trying to replace each Thread.sleep with one of these and then I have the actual events that happen after this, but it does not seem to be waiting at all.
int test = array.get(counter).time;
ActionListener taskPerformer = new ActionListener(){
public void actionPerformed(ActionEvent evt){
}
};
Timer t = new Timer(test, taskPerformer);
t.setRepeats(false);
t.start();
Basically, how do I ensure that the program will wait without giving it any code to execute inside of the timer? Thank you!