我首先序列化一个按钮,然后对其进行反序列化。但在反序列化中,按钮失去了onclick事件和所有。如果我能在这方面得到一些帮助?反序列化时丢失的序列化对象的属性
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt)
{
System.out.println("hello world");
}
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt)
{
try {
f2.createNewFile();
FileOutputStream fos=new FileOutputStream(f2);
ObjectOutputStream oos=new ObjectOutputStream(fos);
oos.writeObject(c);
oos.flush();
System.out.println("done");
cont.remove(jButton2);//serializing above jButton2
oos.close();
}
catch (Exception ex)
{
ex.printStackTrace();
}
}
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt)
{
FileInputStream fis;
JButton b;
try {
fis = new FileInputStream("nnn.java");
ObjectInputStream ois=new ObjectInputStream(fis);
b=(JButton)ois.readObject();
bg.add(b);
bg.revalidate();
bg.repaint();
}
catch (Exception ex)
{
System.err.println("error");
}
}
以上bg是面板到我加入反序列化的按钮B – Aditya
是什么''中oos.writeObject(C)C';在反序列化' –
你说”按钮失去了它的onclick事件和所有“ - 什么是?什么迷路了?你应该知道序列化只保存一个Onject状态(变量内容)而不是它的类(方法和逻辑所在的地方) –