0

I have written jFrame window (newUserPanel), that collects informations about new user. After accepting data it adds new User to ArrayList, that collects all users. Problem is I'd like it to also save (via serilization) my updated ArrayList to file.

(ALL THIS IS UNDER ONE jButton!)

java.awt.EventQueue.invokeLater(new Runnable() {
        public void run() {
            newUserPanel tempPanel= new newUserPanel ();
            dodana.setVisible(true);
            User tempUser= new User();
            tempUser= dodana.getUser();
            listOfUsers.add(tempUser);
        }});


 try {
        ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream("usersList.obiekt"));
        out.writeObject(listOfUsers);
        out.close();
    } catch (IOException i) {
        i.printStackTrace();
    }

I assume it is because newUserPanel is new Thread, so it both happens at the same time. How may I stop serialization until new User is confirmed?

  • 1
    What is the problem ? What exactly are you asking ? Where do you get stuck ? – Robin Aug 27 '13 at 18:19
  • See [The Use of Multiple JFrames, Good/Bad Practice?](http://stackoverflow.com/a/9554657/418556) One of those frames should probably be a modal dialog. – Andrew Thompson Aug 27 '13 at 19:01
  • For example: I had 3 Users in listOfUsers. Now I want to add new User, I use the button, so it calls window in which I can type user-data. Nevertheless serialized will only be those 3 Users which I had previously. Now if I try add 5th User I would get serialized only 4 first. – Vardens Archangel Aug 27 '13 at 19:26

0 Answers0