0

Hi,
I need a little help, i found out to repeat an action/animation automatically I need to use a timer but im having troubles implementing it into my script.
This is the last few part of the action...

public void slowMoveVertical ()
{
sun.slowMoveVertical(-100);
}

Now I what I want it to do is stop, then repeart the same action after a few seconds.

What im basically trying to do it create a sunset which rises but I don't want to go to the top in one action, I want it to stop for a second, while I change some other objects then rise again.

3
Contributors
3
Replies
6
Views
9 Years
Discussion Span
Last Post by Ezzaral
0

You can control that easily by creating a small inner class for your timer action like so

private class TimerAction extends AbstractAction{
    boolean wait=false;
    
    public void actionPerformed(ActionEvent e) {
        if (!wait) {
            System.out.println("moving stuff");
        }
    }
    
    public void wait(boolean wait){
        this.wait = wait;
    }
}

You'll need to keep a reference to it at the class level

TimerAction timerAction;

and when you create your Timer, add it like so

timerAction = new TimerAction();
Timer timer = new Timer(500, timerAction);
timer.start();

You can then pause or unpause it when needed by calling

timerAction.wait(true);  // to pause
// or
timerAction.wait(false); // unpause

If you need to change object position variables you can do that in your TimerAction class as well.

0

Your question isn't clear and is unrelated to this particular thread. Please create a new thread with a more specific question that describes what you are wanting to do.

This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.