• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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..
 
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic