This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

how to pause a animation and change the speed using a slider  RSS feed

 
kartik rathore
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi i am building a animation program which has a button to increase the animation and also a slider which does the same job along with that have a pause button to paus ethe animation..

also i have a slider which is also used to control the rate of animation.

i would appreciate if any one could part me some wisdom over the above items

thanks..
 
Craig Wood
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would add that the Button's actionlistener shouldn't refer to the slider at all that doing so would lead to overly tight coupling. Better would be for the a button to change the animation's Model and have the slider observe the model via a ChangeListener and then make changes to the Slider if the model changes.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!