For Programmers: Free Programming Magazines  


Home > Archive > Java Beans > November 2005 > XMLEncoder and superclasses









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author XMLEncoder and superclasses
awahl@yahoo.com

2005-11-10, 7:56 am

Hello,


I have derived a class from JDialog that I would like to serialize via
the XMLEncoder

public class DerivedDialog extends JDialog {
JTextArea text = new JTextArea();
public DerivedDialog () {
setDefaultCloseOperation(DISPOSE_ON_CLOS
E);
getContentPane().add(text);
setSize(300, 300);
setVisible(true);
}
}

with
DerivedDialog dialog = new DerivedDialog();
XMLEncoder e = new XMLEncoder(System.out);
e.setPersistenceDelegate(GauchoDialog.class,
e.getPersistenceDelegate(JDialog.class));
e.writeObject(dialog);
e.close();

I would have expected that the text written in the TextArea would have
been also serialized in the XML. As it is done when I don't derived
JDialog

with JDialog dialog = new JDialog();
JTextArea text = new JTextArea();
dialog,.getContentPane().add(text);
dialog,setSize(300, 300);
dialoh.setVisible(true);

How can I make this inherited class behave towards XMLEncoder as did
JDialog?

Thank you

awahl@yahoo.com

2005-11-10, 6:58 pm

Hello again,

I added 2 methods setTextA(String txt) and getTextA()

JTextArea text = new JTextArea();

public String getTextA()
{
return text.getText();
}

public void setTextA(String txt)
{
text.setText(txt);
}
What I see that is then the XMLEncoder writes the object as XML. It
creates a copy of the created Dialog as a consequence I have 2 windows
on the screen.

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com