How to save current state of graphics on JPanel [duplicate]
问题 This question already has answers here : How to serialize Java 2D Shape objects as XML? (2 answers) Closed 6 years ago . I have a program that lets the user add rectangles and circles to JPanel using Graphics. What I want to be able to do is save the current state of the current JPanel (i.e. all of the shapes and their locations) into a file and be able to load that file back and restore that state. I have a Shapes class that extends JPanel and does all of the drawing and keeps track of the