0

执行SaveDialogclass setVisible(true) 行时出现以下异常。

当用户点击保存按钮时,该程序将启动。然后它将在尝试保存序列化对象数据时显示状态对话框。

public class SaveController implements ActionListener,Serializable{
    private JButton = new JButton("Save");
    public SaveController(){
         saveButton.addActionListener(this);
    }
    actionPerformed(ActionEvent ae){
       if(ae.getSource == saveButton){
             new saveDialog();
       }
    }
}

public saveDialog extends JDialog{
    public saveDialog(){

         SwingUtilites.invokeLater(new Runnabe()(
            public void run(){
                   // set up gui layout...add status lister
                   pack();
                   setVisible(true);// this is where it crashes
            }
         }
         SaveTask task = new SaveTask();
         task.addEventListener(this);
         task.execute()
     }
}

public class SaveTask extends SwingWorker<void,void>{

    public void doInBackground(){
        File f = new File("file");
        f.createNewFile();
        OutputStream file = new OutputStream("file");
        OutputStream buffer = new BufferedOutputStream(file);
        ObjectOutput output = new ObjectOutputStream(buffer);
        output.writeobject(object);
    }
}
4

0 回答 0