• Post Reply Bookmark Topic Watch Topic
  • New Topic

animation not running smoothly  RSS feed

 
jeevansai jinne
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wrote a code for a bouncing ball but the motion of ball is not going periodically it is moving fast at a place slow somewhere ,Can someone tell why is this happening

 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because 10 milliseconds is too frequent and the screen display can't keep up with it. I believe that possibility was mentioned in the other thread you had about this problem, too.
 
jeevansai jinne
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
even though i increased the time same thing happens
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your overridden paintComponent method should call "super.paintComponent" as its first action.
 
jeevansai jinne
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what should i do after calling super.paintcomponent
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
jeevansai jinne wrote:what should i do after calling super.paintcomponent


What you're already doing. Except, why do you repeatedly create a new ImageIcon every time you redraw the panel? It's the same icon every time, so you should create it only once.
 
jeevansai jinne
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
but what is the use of calling super.paintcomponent , i should create background image every time else previous instance of ball is not removed and instead of a moving ball a line in the path of ball is formed,you can try it yourself
 
Campbell Ritchie
Sheriff
Posts: 53779
128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is because you are not calling super.paintComponent.
It returns the display to its “default” appearance.
 
jeevansai jinne
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If i use super.paintcomponent and draw the background image only once then the background is white and image is not forming , still the motion of ball is not periodic
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't recall anybody suggesting that you should only draw the background image once.

At any rate the problem is with your code somewhere. And notice that you've made some changes to what you originally posted, so nobody but you knows what code you're asking about. But you could fix that by showing us the code that you have now... doesn't that make sense to you?
 
jeevansai jinne
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Campbell Ritchie
Sheriff
Posts: 53779
128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Start by indenting the code consistently so we can actually read it. We have some suggestions here. And use correct conventions for class names.
You were told that super.paintComponent(g); should be the first line in the method. You were also told that 10ms is too quick for repainting. What on earth does the bit about if (j==0) mean?

You have been told quite a lot which you seem insistent on ignoring. Why?
 
jeevansai jinne
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Campbell Ritchie
Sheriff
Posts: 53779
128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your code look as if you were guessing and only doing something when we tell you about it.
 
Les Morgan
Rancher
Posts: 752
17
C++ Java MySQL Database Netbeans IDE Oracle Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your code satisfactorily generates a ball that travels from the upper left to the lower right of the dialog that it produces. I am running it on an 8 core machine with 32GB of ram though, so my thoughts are that you are running into a resource problem on your local box causing your animation to pause or slow in places, then jerkily struggle to make it up.

Animation done in the way you are doing is a cooperative effort, the repaint is called and the time sharing resources on your box need to cooperatively share what is going on. This can result in unexpected timing results. It will not make much of a difference if you run fast or slow delays, if your system wants resources you are going to stop and wait. There is a manual refresh scheme available in Java that takes control of the video card. I would suggest a little more experience before going there--when you start trying to control hardware, you have much more dire of results when mistakes are encountered.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!