• 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

What does a Graphics object actually represents?

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok, I'm not even sure if that is the right question to ask. I've been confused by what is A Graphics object for a while now, I used to think that it is simply a tool to use to change colors and draw to specific container(ie JFrame, JPanel). However, I've been studying buffering(triple, double, flipping...etc) and how it works for 3 days now, and my confusion has only increased. for instance, why when we need to draw to the buffer(ie BufferStrategy, BufferedImage) we get its own graphics object to draw to it and then we project it to the screen? does the Graphics Object represent the drawing surface (ie the JPanel it self if we're using one to draw custom painting via JPanel#paintComponent(Graphics g)) ? and so when we're getting the graphics object of a buffer, do we actually get its drawing surface to paint on? Please somebody explain, any help is appreciated Thanks

so generally speaking if we are using a JPanel and we say bufferedImage#createGraphics and use that graphics object to draw to, we would not be drawing to the JPanel but to the BufferedImage correct?
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am no expert, but the Graphics class is abstract. So you never have an actual Graphics object...you have some other object type that is a sub-class of the Graphics object.
 
abdul halim
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes I understand that it is abstract, I was referring to the object that you get when you call createGraphics() or createDrawGraphics()
 
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

if we are using a JPanel and we say bufferedImage#createGraphics and use that graphics object to draw to, we would not be drawing to the JPanel but to the BufferedImage correct?



Correct.

And then if you actually want the BufferedImage to be displayed on the panel then you use the Graphics object passed to the paintComponent() method of the JPanel to paint the BufferedImage on the panel.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic