I've drawn some things on a JPanel. I'd now like to retrieve the graphics (images, shapes, etc) I've drawn on the panel and pass this data to another component to add to it. If I use the getGraphics() method of the JPanel however I'm returned a NullPointerException. What am I doing wrong? Here's an example of what I want to do:
I hope this makes sense. I realise one workaround is to call the paintComponent method of myPanel2 from the paintComponent method of myPanel, passing the graphics down directly, however this ends up getting messy and forces me to store myPanel2 in a location which makes it accessible from myPanel's paintComponent method. Any help much appreciated.