Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Help Saving Objects for this Program  RSS feed

 
Ben Jass
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the code below, when I click on the JButton "Set Up", it brings up a new JFrame with options on making things, I won't get that detailed in it. There are buttons and text fields inside the Set Up JFrame. I want to save these objects so every time after the first initial click of the button, it will save the which option you chose, and what you typed in the text field. I'm know the coding behind saving objects and stuff, but I don't know which objects to save and when to write the objects to a file stream and when to read the file stream. If someone could point this out to me which objects I should save (so that all the button options are saved, and the text is too), and where to put the input stream and the output stream. I know how to code it, I would just like an outline if it isn't too much to ask for.

Couple quick things to note before looking at this code to understand it:
~ I have 3 sets of buttons added to ArrayList's, I want the button options to be saved.
~ I have 2 text fields, I want the writing inside to be saved.
~ When I click the apply button, that dispose's the Set Up JFrame and saves the objects

 
Joe Ess
Bartender
Posts: 9425
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ben Jass wrote: . . . If someone could point this out to me which objects I should save (so that all the button options are saved, and the text is too), and where to put the input stream and the output stream. I know how to code it, I would just like an outline if it isn't too much to ask for.


We'd be glad to help you out if you have a question so long as you follow some simple guidelines, but telling you how your program is supposed to work isn't really what we do.
 
Ben Jass
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I understand now that I was asking way too much. Can you give me an idea on how to save let's say an ArrayList named exampleList when you close the setUp JFrame (clicking Apply), and then loading that object when you reopen the set up JFrame?
 
Ben Jass
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm still having trouble, here I'll explain quickly what I'm trying to do, for starters I'm going to try to save the method name (theMethodName) after I put it in the JTextField and click apply, so that when I open up the frame that holds that JTextField again, it still has that name inside the JTextField.

I set up a static int so that it adds 1 every time you click the set up button, this means that I don't have to recover any objects if the static int is == 0.

This is the first thing that executes when someone clicks the set up button:


This is what happens when I click the apply button (activates the action listener):

The string doesn't save when I try to open the set up frame again..
 
Joe Ess
Bartender
Posts: 9425
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sounds like this entry in the FAQ.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!