views:

58

answers:

3

Actually, I am creating a new application through java. I want that if a user opens a previously created file in my application then the condition of my application should be restored to where he left while saving that file. --Thanks in advance

A: 

Take a look on Command Design Pattern. If you treat every user input as a command and save a list of commands, after restarting just reiterate through the list and rebuild the state.

For this purpose Memento can be used as well.

Boris Pavlović
A: 

Add the information describing the condition of the application to the file when you create it. Then, when you load the file, load this information as well and use it to recreate the state of the application. Create whatever methods are necessary to support this.

Erick Robertson
+1  A: 

I think you've got these things:

A). A User Interface of some sort, so some text areas, drop down lists and such.

B). Some Java Objects whose contents reflect what's in those UI pieces.

C). Something in a file that represents those Java Objects. Maybe you just serialized them?

It's not clear what your problem is.

Going from File -> Objects is just a matter of deserializing. Should be not much harder than writing the file.

I guess normally you have changes in UI make changes in your objects and perhaps you're wondering how to get the UI to initialise to reflect the objects you just read from file.

If that is the problem then it's hard to help unless you tell us what technologies you're using. In some cases the UI Widgets quite naturally update to reflect the content of the backing objects, in others there may be a bit more work. You'll have to give us more detail of where you're stuck.

djna