• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Graphics

 
Jian Yi
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why say Graphics can't be instantiated? Isn't g an instance of Graphics in paint(Graphics g)?
Thanks,
Jenny
 
Jose Botella
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic