• Post Reply Bookmark Topic Watch Topic
  • New Topic

Painting of JPanel

 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, to draw into a JPanel, I would always implement the method:


But I saw some code that seems to be more cpu friendly:


I'm not sure what the pros and cons of changing to the second way are, any thoughts?
 
Rob Camick
Ranch Hand
Posts: 2700
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, to draw into a JPanel, I would always implement the method:


Maybe because that is the way the Swing tutorial recommends you do custom painting?

But I saw some code that seems to be more cpu friendly:


Why would you ever think that is more CPU friendly?

That piece of code is for AWT and should not be used with Swing.
 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cause I'm building a rubiks cube, when I rotate it very quickly, the cpu is drained slightly less with the paint/update methods, so I guess it is more efficient, or does it have a problem over paintComponent ?
 
Rob Camick
Ranch Hand
Posts: 2700
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Read the article on Painting in AWT and Swing for more information and decide which approach you want to use.
 
mark goking
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
colin, rob is right

if you use awt, you'd heavily use the paint() method since that is the only method available for painting.

with swing , you would have to use the paintComponent() method
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!