How do I get the g element from a jpanel in java, how can I pass it to another object draw on it and pass it back. Just to be clear, I can use g or graphics to draw on the jpanel; but cannot seem to pass this to another object to draw on it else where. Thanks in advance, I have searched for a solution and cannot find anything, might be that I am not using the right terminology, sorry.
Share
The cleanest way to pass a
Graphicsobject from aJPanelto another (helper) object is to pass the object from thepaintComponentmethod. This way, you can be sure that the object will always be instantiated.