Beginner: Restore previously serialized JFrame-object, how?
- by elementz
Hi all.
I have managed to serialize my very basic GUI-object containing a JTextArea and a few buttons to a file 'test.ser'.
Now, I would like to completely restore the previously saved state from 'test.ser', but seem to have a misconception of how to properly deserialize an objects state.
The class MyFrame creates the JFrame and serializes it.
Now I tried to deserialize like so:
public class Deserialize {
static Deserialize ds;
MyFrame frame;
public static void main(String[] args) {
try {
ds.deserialize();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void deserialize() throws ClassNotFoundException {
try {
ObjectInputStream ois = new ObjectInputStream(new FileInputStream("test.ser"));
frame = (MyFrame) ois.readObject();
ois.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Maybe somebody could point me into the direction where my misconception is?
Thx in advance!