You can make a view class that renders the animation and a controller class that
encapsulates the animation code. The controller drives the animation by updating
member variables in the view class.
Set up your slider to control the time delay for your controller class. Set up
the button to decrement the delay value and then set the new delay value in
the slider.
Making changes to the slider value will cause it to generate ChangeEvents which
you'll want to avoid. You can make a member variable boolean in your controller
class and use it to avoid these unwanted ChangeEvents. In the buttons
ActionListener, when you change/decrement the delay value and are going to set
the slider value, change the boolean before and after changing the slider value.
In the sliders ChangeListener you can use this boolean to guard the code that
responds to the events.
The
pause method can cause the
thread to terminate without
resetting/reinitializing the member variables in the view class. A
stop method can terminate the thread and reset the view variables. To stop the thread
you can use a
boolean in a
while loop and toggle its value to exit
the loop. Then you can either
interrupt the thread, if it is non-null, or
call
join on it and allow it to terminate on its own.