How to serialize a window or form
Maybe serialization is not supposed to work this way, but I want to serialize an entire window (objects and all) to a file, and then de-serialize...this code is close:
void saveIt() {
try {
FileOutputStream out = new FileOutputStream("file.dat");
ObjectOutputStream s = new ObjectOutputStream(out);
s.writeObject(myWindow );
s.flush();
s.close();
myWindow .dispose();
} catch(IOException ioe) {
System.err.println("Save failed!");
ioe.printStackTrace();
}
};
void openIt() {
try {
FileInputStream in = new FileInputStream("file.dat");
ObjectInputStream s = new ObjectInputStream(in);
JInternalFrame myWindow = (JInternalFrame)s.readObject();
in.close();
myWindow .show();
} catch(Exception e) {
System.err.println("Load failed!");
e.printStackTrace();
}
};
When I debug this, the 'myWindow ' reference after loading seems to be valid, and I can actually add objects to it...but it's just not there! I also tried 'repaint' and 'pack' and other methods to try to get the window to show up, but to no avail.
I also tried XMLEncode and decode with similar (but different) results...
Anybody?
Thank you,
JR
Message was edited by:
johnrule
Fixed a typo...

