If this is a Swing application, then you should either be drawing to a BufferedImage, in which case you'd get the BufferedImage's Graphics object via getGraphics()
, or you would be doing this drawing in a JPanel's paintComponent(Graphics g)
method and would use the Graphics object passed into the method by the JVM.
To tie this in to a JButton's being enabled or not, I'd add a ChangeListener to the button's model, and call repaint if the enabled property changes, and then would have an if block in the JPanel's paintComponent method and base whether or not to paint the shapes on the button's enabled state.
For more detailed help, consider posting an sscce.