This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes graphics object Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "graphics object" Watch "graphics object" New topic
Author

graphics object

ima clark
Greenhorn

Joined: Apr 23, 2002
Posts: 19
I have a class that has an inner class with a method called paintComponent(Graphic g) that accepts a Graphic object as a parameter. I am trying to call this paintComponent(Graphic g) somewhere else in the program but am not sure how to deal with the graphics object?
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
The system knows what it's graphics context is. You just need to ask it to let you in on the secret.
If you want a graphics object for the object that you are in (like if you want to call paint or something) you just do a getGraphics() and the method returns a Graphics object.
To call your method you would do:
paintComponent(getGraphics()) //gets the graphics for "this"
If you want the Graphics for a different component you do something like:
Graphics g = myComponent.getGraphics();
or whatever.


"JavaRanch, where the deer and the Certified play" - David O'Meara
William Barnes
Ranch Hand

Joined: Mar 16, 2001
Posts: 986

Post some code - and please use the *code* tags.


Please ignore post, I have no idea what I am talking about.
ima clark
Greenhorn

Joined: Apr 23, 2002
Posts: 19
Thank you !!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: graphics object