Graphics g = new Graphics();
isn't going to work (as I'm sure you're aware) as the class is abstract.
Custom painting in Swing is done by overriding the paintComponent
of a component that extends from JComponent
(like JPanel
) and using the supplied Graphics
context to paint to.
Take a look at Performing Custom Painting and Painting in AWT and Swing for more details
You should also beware that painting is a destructive process, meaning that each time paintComponent
is called, you are expected to update everything that you need painted.