Sign in to follow this  
Concentrate

Java Serializable

Recommended Posts

Ok, this is my AnimationSaving class :

public class AnimationFileSaver {
public AnimationFileSaver(String filePath){
this( new File(filePath));
}
public AnimationFileSaver(File file){
//save file
try{ _tryToSave(file);}
catch(java.io.IOException e){
e.printStackTrace();
}
}

private void _tryToSave(File file)throws java.io.IOException{
java.io.FileOutputStream stream = new java.io.FileOutputStream(file);
java.io.ObjectOutputStream outputStream = new java.io.ObjectOutputStream(stream);
//save data into file
outputStream.writeObject(animationeditor.Controller.AnimationMainController.windowController);
outputStream.writeObject(animationeditor.Controller.AnimationMainController.frameController);
}
}




and my loader class

public class AnimationFileLoader {
public AnimationFileLoader(String filePath){
this( new File(filePath));
}
public AnimationFileLoader(File file){
//save file
try{ _tryToSave(file);}
catch(java.lang.Exception e){
e.printStackTrace();
}
}

private void _tryToSave(java.io.File file)throws java.io.IOException, java.lang.ClassNotFoundException{
java.io.FileInputStream stream = new java.io.FileInputStream(file);
java.io.ObjectInputStream inputStream = new java.io.ObjectInputStream(stream);
//save data into file
AnimationMainController.windowController = (AnimationWindowController)inputStream.readObject();
AnimationMainController.frameController = (OnionSkinningController) inputStream.readObject();

}
}



The windowController contains the main app window, and the frame controller
has a list of frames used in th program. The above class works partially, but
not fully. The objects that were saved are loaded into the screen, but they
loose their capability of interactions with the user. More over, when I debug
it, my container that holds a list of shapes seems to be empty, but the screen
still shows the shape. Is there something more I should know about java.io.Serializable ? I could show more code, if I need to. Thanks.

Share this post


Link to post
Share on other sites
Does the saver and loader need to implement serializable? And I'm not sure whats the convention in java. Just regular naming I guess.

These classes implements java.io.Serializable

AnimationMainController.windowController; AnimationMainController.frameController


Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this