This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes What's really going on with the graphics context? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "What Watch "What New topic
Author

What's really going on with the graphics context?

Adam Ratcliffe
Greenhorn

Joined: Aug 04, 2000
Posts: 13
Hi,

When drawing code is implemented in an event handler a graphics context is obtained using the getGraphics() method.




Would I be correct in assuming that the results of the drawing operation(s) are stored in this graphics context object, and the reason that the drawing history isn't available to the paint() method when it is called by the GUI thread, is because the paint() method makes calls on an independent graphics context object?




Similarly the update() method takes a graphics context method as a parameter, however the description in the Java API of the repaint() method has nothing to say about repaint() supplying a graphics context object as an argument to update when it calls it.




Can anyone throw some light on what's really going on here?


Kind regards,

Adam Ratcliffe
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12671
    
    5
A Graphics object does NOT store any of the results of drawing, those go to whatever you are drawing on. Look it up, a Graphics object owns things like color and font and a clipping rectangle.
The repaint call requests that the JVM repaint a Component or part of a component. When the JVM gets around to it, a special GUI Thread calls update with a Graphics object obtained from the JVM.
Generally speaking, the safest thing to do is to do all of your drawing to the screen in the paint method.
Bill

Java Resources at www.wbrogden.com
Adam Ratcliffe
Greenhorn

Joined: Aug 04, 2000
Posts: 13
Hi Bill !
Thanks for your clear explantion of the graphics context object
- I think I was just getting a little too complicated about it :-)
Kind regards,
Adam
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: What's really going on with the graphics context?
 
Similar Threads
Question using Paint method
Painting in a Frame.
Graphics Class
Graphics Object & Graphics Context
Graphics g