I'm building an animation to represent array operations. So far I've constructed an animation on a an object represented as a drawn rectangle (index) which is deleted, and the remainder of the indexes to the right are left-shifted to occupy the correct index. For each rectangle index to be shifted, I create an animation for that particular object.
I want to be able to start the animation for the next index to be shifted as soon as the first is finished. I attempted a while loop to check if the animation is still running but this actually prevents the current animation being displayed because of a busy wait loop. After having looked at the Animator class in the API, I've found a relevant method:
void await() Causes the current thread to wait until the animation completes, either on its own or due to a call to stop() or cancel(), unless the thread is interrupted.
In this case, what is the current thread? I know that the Timing-Framework runs its own timing thread, so is this what it's referring to?
How should I write another block of code, that deals with building the next index animation wait on the first using this animator method?
Thanks.
2 Answers
Since this is a Swing GUI, I think that you'll be much better served by using a Swing Timer for your animation as this way, all animation will be done on the Swing event thread and without tying down and freezing this important thread. You could attach some sort of notification with a listener to see when the animation is complete, perhaps by adding ChangeListener or PropertyChangeListener support for your animation code.
If you're using Timing Framework, version 1 has a TimingTarget interface which can be attached to a Animator instance.
This will provide event notification about the state of the Animator.
Apart from providing "tick" call backs it also supplies begin and end.
You could put a chain of Animators together, starting the next one when end is called.
Unfortunately, I've not had time to update my libraries to use the newer versions, so the actual interfaces and methods may have changed.