It's not a secret anymore!
The moose likes Swing / AWT / SWT and the fly likes java.awt.Graphics and java.awt.Graphics2D Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "java.awt.Graphics and java.awt.Graphics2D" Watch "java.awt.Graphics and java.awt.Graphics2D" New topic

java.awt.Graphics and java.awt.Graphics2D

Victor M. Pereira
Ranch Hand

Joined: Mar 02, 2012
Posts: 50
Out of simple curiosity who implements the actual methods that draw? Since the draw(Shape S) from the java.awt.Graphics2D is an abstract method and I heven't been able to find something that implements logic to it.
I got curious!

Victor M. Pereira
Stephan van Hulst

Joined: Sep 20, 2010
Posts: 4628

Well, one thing you could do is try and track down the point where the actual Graphics instance is created. A point you can start is the source code of one of the JFrame.repaint() methods.

The mind is a strange and wonderful thing. I'm not sure that it will ever be able to figure itself out, everything else, maybe. From the atom to the universe, everything, except itself.
Victor M. Pereira
Ranch Hand

Joined: Mar 02, 2012
Posts: 50
Thanks I'll try that and post the result of the experiment. I only hope It doesn't end in the Java ByteCode.
Darryl Burke

Joined: May 03, 2008
Posts: 5115

All the interesting methods of concrete implementations of Graphics/2D are in native code, and the concrete classes themselves are (possibly platform-dependent) proprietary com.sun... classes. Do a sysout of getClass() in a painting method override and you can get the class name. No, you won't find the source of that class in

If you're interested in the sequence of painting activities, look at RepaintManager.

The repaint() method merely queues a paint event in the EventQueue.

luck, db
There are no new questions, but there may be new answers.
I agree. Here's the link:
subject: java.awt.Graphics and java.awt.Graphics2D
jQuery in Action, 3rd edition