Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

What does a Graphics object actually represents?  RSS feed

 
abdul halim
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • 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?
 
fred rosenberger
lowercase baba
Bartender
Posts: 12440
42
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • 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
  • 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()
 
Rob Camick
Ranch Hand
Posts: 2752
11
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!