Hi I have written a small java program based on swing application. Now I want to store the object of my swing application (jframe) in database and I want to retrieve the same from database when its necessary. during retrieve i want to get the same object. I am using sqlite as database
How to achieve this functionalit开发者_如何学Pythony
Thanks Sunil Kumar Sahoo
Are you sure you want to store the view and not the Model? Another method except for Preferences is to use XMLEncoder
I don't know about sqlite, but Preferences
is a a good way to store information about your JFrame
.
To my knowledge it's not actually possible to save the JFrame to a database. Whether you do it yourself or with some kind of library the way it works is that you save to the db all the information you need to recreate your JFrame.
A JFrame implements Serializable so theoretically it is serializable as an ObjectStream you could use ObjectInputStream and ObjectOutputStream and write the stream to the database.
All components in the JFrame should also be serializable. However it is not really advised to do this since the api says "Serialized objects of this class will not be compatible with future Swing releases."
精彩评论