Timer in Java swing
Posted
by
Yesha
on Stack Overflow
See other posts from Stack Overflow
or by Yesha
Published on 2013-06-28T04:16:46Z
Indexed on
2013/06/28
4:21 UTC
Read the original article
Hit count: 113
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!
© Stack Overflow or respective owner