saving information in forms
Hi i hace been able to save information in forms after moving from one form to another in java swing applcation. i got rid of the dispose() code. however is there a way to actually keep the cutrrent values when i exit the application and open it again with the values that were entered before still there in the textfields. thank you
> Hi i hace been able to save information in forms
> after moving from one form to another in java swing
> applcation. i got rid of the dispose() code. however
> is there a way to actually keep the cutrrent values
> when i exit the application and open it again with
> the values that were entered before still there in
> the textfields. thank you
Please check with Cookies and Session, for your information.
To save the information in a Form/Dialog when you exit the Swing Application.
Make your form class implement java.io.Serializable
To save the form:
See http://exampledepot.com/egs/java.io/SerializeObj.html
To read the form:
http://exampledepot.com/egs/java.io/DeserializeObj.html?l=rel
To save (using a different filename of each saved form):
object = instance of the form to save
try {
// Serialize to a file
ObjectOutput out = new ObjectOutputStream(new FileOutputStream("filename.ser"));
out.writeObject(object);
out.close();
} catch (IOException e) {
}
To read back
Object obj;
try {
// Deserialize from a file
File file = new File("filename.ser");
ObjectInputStream in = new ObjectInputStream(new FileInputStream(file));
// Deserialize the object
obj = in.readObject();
in.close();
} catch (ClassNotFoundException e) {
} catch (IOException e) {
}
if (obj instanceof 'your form's class') {
// Cast it to the correct class and away you go
}
Wasn't thinking too hard yesterday.
Rather than make the form serializable create a new class that holds the relevant information for the form to be re-populated and make this serializable and save it. When the form closes save the information from the form into the class and save the class. When the form opens read the information from the class and re-populate the form.