Graphics Context?
posted 24 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
I have a couple of questions concerning the Graphics Context. Perhaps someone would be kind enough to help this newbie. It seems that whenever we want a graphics context we need to use getGraphics() rather than new Graphics(). I assume that this is because the Graphics object that is returned in the former is chock full of necessary info such as the clip region for the component, etc (the context part of "Graphics Context")... am I right in this assumption?
But how does the Graphics context know which component we want it to be associated with? If I have a frame with two panels, how does the Graphics context know I want it to be associated with the first panel and not the second one?
Thanks in advance
Dan
But how does the Graphics context know which component we want it to be associated with? If I have a frame with two panels, how does the Graphics context know I want it to be associated with the first panel and not the second one?
Thanks in advance
Dan
posted 24 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Because you call getGraphics() on the component you want to get the graphics of!
If you have a frame with two panels ( panel1 and panel2 ) panel1.getGraphics() gets the graphics context of panel1, panel2.getGraphics() gets the graphics contect of panel2, and getGraphics() gets the graphics context of the frame ( if your frame is your main class... )
You are pretty much right about the reason why there is no new Graphics() call... I think that it is also due to the graphics context dealing with alot of native resources...
-Nate
[This message has been edited by Nathan Pruett (edited July 31, 2001).]
If you have a frame with two panels ( panel1 and panel2 ) panel1.getGraphics() gets the graphics context of panel1, panel2.getGraphics() gets the graphics contect of panel2, and getGraphics() gets the graphics context of the frame ( if your frame is your main class... )You are pretty much right about the reason why there is no new Graphics() call... I think that it is also due to the graphics context dealing with alot of native resources...
-Nate
[This message has been edited by Nathan Pruett (edited July 31, 2001).]
-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Dan Temple
Ranch Hand
Posts: 93
posted 24 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Okay that makes sense! (One of the reasons I like Java)
Hey! I'm a ranch hand now!!! What does this gig pay anyway? LOL
Dan
Hey! I'm a ranch hand now!!! What does this gig pay anyway? LOL
Dan
| Sometimes you feel like a nut. Sometimes you feel like a tiny ad. The new gardening playing cards kickstarter is now live! https://www.kickstarter.com/projects/paulwheaton/garden-cards |








