Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Serializing a Series of JPanels

 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic