我写了一个程序,是在文本框中输入了数字,点确定可以保存一个文件,这个文件是保存对像序列化的文件,可 是运行出错 ,程序目的是在文本框中输入内容,点确定下次打打开时文本框的内容是上一次保存的内容.
请高手帮我改一下.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;public class serializableDemo implements Serializable,ActionListener
{
     JFrame frame=new JFrame("保存设置");
     JTextField text1,text2;
     transient JButton button=new JButton("确定");
     ObjectOutputStream out;
     ObjectInputStream in;
   
      public serializableDemo()
       {
           Container cp=frame.getContentPane();
           cp.setLayout(new GridLayout(1,3));
           text1=new JTextField(10);
           text2=new JTextField(10);
           cp.add(text1);
           cp.add(text2);
           cp.add(button);
           button.addActionListener(this);
           frame.setBounds(300,300,200,100);
           frame.pack();
           frame.setVisible(true);
           frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
           }
       public void actionPerformed(ActionEvent e)
        {
           button.setEnabled(false);
           try{
           out=new ObjectOutputStream(new FileOutputStream("p.ser"));
           out.writeObject(text1);
           out.writeObject(text2);
           out.close();
                 }catch(IOException e0){}
           button.setEnabled(true);
          }
        public void fangfa()
          {
              String s1,s2;
                  try{
               in=new ObjectInputStream(new FileInputStream("p.ser"));
               text1.setText(s1=(String)in.readObject());
               text2.setText(s2=(String)in.readObject());
               in.close();
               }catch(ClassNotFoundException e1){}
                catch(IOException e2){}
          }
    public static void main(String[] args)
{
        serializableDemo diao=new serializableDemo();
        diao.fangfa();
}
}