• Post Reply Bookmark Topic Watch Topic
  • New Topic

Serializing a Series of JPanels  RSS feed

 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all, I have an Applet that displays a familty tree. Another application is used to generate the family tree as a series of panels in a grid format. The Applet reads the serialized JPanels and displays them. I use serializartion of the panels instead of the underlying data because placing the Person objects on the panel is a recursive function that may take a while based on family size, so to save time, I seriealized the final product, after all panels are created and placed...
Anyway, the problem is that JComponents that are serialized are not compatible with other versions of the Java Run Time, so if I use JRE_1.4.2 to make the family tree to begin with, only 1.4.2 viewers will work. This means that those with 1.4.1_02, or 1.4.2_01, or whatever the next version of Java will be will not be able to view the Serialized panel...
I tried to use XMLEncoder, which the Java API says is supposed to be used for long term storage, but it seems to only work for JavaBeans.. and I don't think my sub-classed panels are Beans, 'cause I get an InstantiationException whenever I call the XMLEncoder's writeObject method on my top-level panel...
Is there some way I can Serialize JPanels and make them useable from one version to the next? If not, how can I use the XMLEncoder? It seems that I have to have special Developement Kits to make beans, is that true?
Thanks for any help...
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay, I worked this out. Basically, you do NOT need a Bean Developement Kit (BDK) to make JavaBeans, you just have to follow a very strict design pattern --
You must instantiate the object with a no-argument constructor
You must apply all changes to the objects properties using the getter and setter methods.
The class must implement Serializable...
And for the XMLEncoder to work, ALL objects referred to in the Bean must also follow this design pattern, unless that object has only local scope, (for instance, I use Images, but the Images are not Beans, they are held in a static context in another class, and Image references are created and die in the paintComponent method...)
So that solves my problem... by the way, for those that may care, The XMLEncoded JPanel generated in 1.4.2 works with 1.4.1_01 and 1.4.1_02 JREs...
 
Maulin Vasavada
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi steve

Anyway, the problem is that JComponents that are serialized are not compatible with other versions of the Java Run Time, so if I use JRE_1.4.2 to make the family tree to begin with, only 1.4.2 viewers will work.

i have a question related to this. from a servlet i prepare DefaultMutableTree object recursively to build the heirarchical listing of the directories from a given root directory and then pass that DefaultMutableTree object to the applet via objectOutputStream. Now, is it safe to work this way? meaning if i create the DefaultMutableTree object on servlet and then pass it to the applet which might run different version of JRE (tho u can assume higher than 1.3)?
earlier, i created a dummy object called FileEntry and then i was storing the listing in that object, passing FileEntry object to the applet and let applet traverse that object again to build DefaultMutableTree object...
plz let me know ur views...
regards
maulin
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!