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 ...
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.
Joined: Aug 09, 2012
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...
Joined: Mar 08, 2009
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!
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com