posted 19 years ago
You can use the JComponent method getGraphics to get a reference to the graphics context. What you draw with it will not survive past the next system–triggered repainting episode. For persistence, it is recommended that you do all drawing from within the paintComponent method for JComponents.
You mentioned Panel which is an AWT component. For AWT components you use the paint method. It is recommended that we not mix Swing and AWT components.