• 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Swing Animation....

 
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello to all! I have a problem with the animation .... in my program I have 4 images at their speed ... if the first image is scrolling and I click on another image ... does not respect the speed increases ... the speed ... but if before clicking on another image I click "stop" then meets the speed ...

this is code:



where is the error???

Sorry for my English ... I hope I was clear
 
Saloon Keeper
Posts: 5583
213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Paul,

I'm afraid your question is not very clear, no.

There are many remarks to be made, bu first and most important: get your indentation correct!
Without this, it is nearly impossible to follow what is going on. Just look at your code snippet: what do you think it looks like?
I learned myself the following trick, to be applied when a class or method ends in a lot of braces:



Now, for your question about speed. Many things could be wrong here, but the first thing I noticed is this:

See line 30: timer2 has a fixed time interval of 200 ms. In the action there seems to be a constant decrease of the Y value of 1. So where's any speed change supposed to come from?

Well, much more could be said about the code, but I hope you have some clues to get you going.

Greetings,
Piet
 
paul beppe
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i write you all code...so you can understand my problem....



Example: i click to "buttomImage1" and start animation....if i click to "buttonImage2" when the image is in scroolling i can't to "stop" or "restart" the second animation...whay??? i haven't control on button "pause" and "play"...

this is problem...
 
Piet Souris
Saloon Keeper
Posts: 5583
213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Paul,

well, indentation is now a lot better!

I find your code a bit hard to follow, because it is not very well structured. What I suspect to be the trouble is the following:

when you press buttonImage1, then you add anonymous actionlisteners to the pause and play buttons. The same happens when you press buttonImage2.
That means (I think, I have no experience with this) that you now have TWO actionlisteners for both the play and pause buttons.
Adding an actionlistener does just that: add a new actionlistener to whatever was there before. It does not replace the old one(s).
The next thing is that in the AL's you simply redefine a timer by: timer = new(...). I think that the old timer just goes on throwing its old action events, picked
up by the old actionlisteners! Of course, causing a lot of unexpected outcomes.

As I said: since I have never programmed things this way, I can't be sure of my answers. But I should try this:

1) define two actionlisteners for the play and the pause buttons and add these to the two buttons.
2) when pause is clicked, then stop the timer; when play is clicked, restart the timer.
3) in the actionlistener for the two image buttons, first stop the timer, then redefine the timer depending on which button is clicked. Still, maybe it is a lot easier
to define two timers, making sure that at most only one at the time is running

Well, enough for now. Let us know if this was indeed the problem, and whether you got it working. Success!

Piet
 
That new kid is a freak. Show him this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic