Beginner: Restore previously serialized JFrame-object, how?

Posted by elementz on Stack Overflow See other posts from Stack Overflow or by elementz
Published on 2010-04-26T08:29:34Z Indexed on 2010/04/26 8:33 UTC
Read the original article Hit count: 302

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!

© Stack Overflow or respective owner

Related posts about java

Related posts about basic