954,554 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

getGraphics() is bad style?

I am working my way through an online book--Intro to Java Programming by David Eck--and in it he says that it is generally considered bad style to use the getGraphics() method to draw outside of a component's paintComponent method. Does anyone know why this is?

pi_lord12
Light Poster
31 posts since Jun 2010
Reputation Points: 10
Solved Threads: 1
 

Since nobody more knowlegable has answered, here's my attempt.
Swing thinks that it is in charge of what gets painted when because it is responsible for calling the various paint methods. If you go ahead and do painting activities that Swing doesn't know are happenuing then either they won't make it all the way to the screen or they will get over-painted at random by Swing.

JamesCherrill
Posting Genius
Moderator
6,373 posts since Apr 2008
Reputation Points: 2,130
Solved Threads: 1,073
 

Ok, I think I get it... thanks

pi_lord12
Light Poster
31 posts since Jun 2010
Reputation Points: 10
Solved Threads: 1
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: