• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Scott Selikoff
Bartenders:
  • Piet Souris
  • Jj Roberts
  • fred rosenberger

Graphics Context?

 
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).]
 
Dan Temple
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic