Search code examples
javaserializationuser-interfacedeserializationactionlistener

Serialization of JFrame removes JButton's ActionListener - Java


I'm relatively new to serialization, so I created a test application to mess around with it. I serialized a JFrame which had 3 added JComponents: a JTextArea and two JButtons. One button saved the JFrame's state (i.e. serialization) and the other loaded the serialized JFrame (i.e. deserialization).

When I typed a message in the JTextArea, clicked the button to save the state, and then loaded the JFrame from the SER file, I got the exact same object (typed message and all) except that the buttons no longer worked.

Would someone mind explaining why this behaved the way it did?

P.S. I know that it's generally not a good practice to serialize GUI components, but this is for learning purposes only.


Solution

  • I made the class that was implementing ActionListener also implement Serializable, and that fixed the problem right up.