Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Repainting Jpanel timer (60fps) 12% CPU usage

 
Ash Whin
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey guys, I had a thread in another forum but its too long to read so... This ones the extension of the same project I've been working on. I've figured out that lots of the lagginess was coming from the lack of synchronisation and the bad allocation of elements so I corrected that and now the physics code part is a lot better, and I tested the program with and without the JPanel.repaint() and found an increase of 8% CPU to 20% CPU.

The code for repainting goes like this:

 
Les Morgan
Rancher
Posts: 711
17
C++ Java MySQL Database Netbeans IDE Oracle Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What you are saying is not normal.  First off you need to make your program event driven, here is a thread that, I believe, does a decent job of telling how to do event driven. Use a Swing Timer to make your animation loop, it will get rid of your wasted overhead of trying to control your application instead of letting Java do what it was made to do.

Swing Timers also run in a single thread so you don't have overhead eaten up with multiple timers.

I've literally had thousands of objects on a screen and not consumed the resources you are asking about.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic