• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Graphics

 
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic