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.

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.

how to set the moving to a certain place? for top?

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.