aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Graphics Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Graphics" Watch "Graphics" New topic
Author

Graphics

Jian Yi
Ranch Hand

Joined: Feb 01, 2002
Posts: 127
Why say Graphics can't be instantiated? Isn't g an instance of Graphics in paint(Graphics g)?
Thanks,
Jenny
Jose Botella
Ranch Hand

Joined: Jul 03, 2001
Posts: 2120
calling g.getClass().toString() within paint returned: sun.java2d.SunGraphics2D
I think Graphics objects are so important/heavy that Sun prevented us from instantiating them, in order to avoid that we could forget to release the object. We, as programmmers, don't create directly new Grahics objects, we obtain references to previous and automatically created ones.


SCJP2. Please Indent your code using UBB Code
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
It's my understanding that the actual graphics object might be different from platform to platform. The abstract Graphics class serves as the base class for the actual objects used. So, on a Mac, the actual object used could be of type MacGraphics (or some such thing) while on a Windows machine the actual object used could be of type WinGraphics (not actual classes). These machine specific classes would implement the machine specific methods, both extending the abstract base class Graphics, and then that whole polymorphism thing (late binding) does it's job.


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Graphics