Solved

How to memorize String value into jTextField

Posted on 2011-02-27
6
482 Views
Last Modified: 2012-05-11
When I open GUI, all values entered during previous session into text fields disappear.
Please advice how to remember last entered value into text field, so I don't need re-enter it again.
Thank you
0
Comment
Question by:gbcbr
  • 3
  • 3
6 Comments
 
LVL 47

Expert Comment

by:for_yan
ID: 34992362
If you want to have on the start of application the same values
in textfields which user entered last time you need to persist
what user eneterd previous time in the file or i database
0
 

Author Comment

by:gbcbr
ID: 34992373
I heard a lot about persistence, but for me now it's black box.
Can you suggest how to start to develop it?
0
 
LVL 47

Accepted Solution

by:
for_yan earned 500 total points
ID: 34992545
Well, then it si totally different question - if you want to
learn perisistence for some parcatical reason, maybe you want
to read about object serialization and store you objects in files or database,
you may use Hibernate which does for you part of yoyr tasks or use Persistence API:
http://java.sun.com/developer/technicalArticles/J2SE/Desktop/persistenceapi/

But if your goal is to make sure next time folks start your program
they see the same textfileds they left it when tey last used it then all this stuff
is more of an overkill.

Basically, as a reasonable middle way, I'd suggest to make a Properties
object to collect all tese data in that object when you
run through your program and befiore you exit to serilize this object
into configuartion file, maybe to write it instead into
XML file or .property file is a better option then you can modify it in the meantime.

And then on startup you read it in.

There is an example of such thing in this link (click on Listing A) for the code:

http://www.techrepublic.com/article/store-your-apps-configuration-information-with-java-properties/1049436
 



 
0
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 

Author Comment

by:gbcbr
ID: 34992599
I suppose that is what I need in my case. Just I need to understand how to connect it to my GUI.
I'll study it tomorrow.
Thank you.
0
 
LVL 47

Expert Comment

by:for_yan
ID: 34992624
I think you rather think of this stuff as the data ssociated not with GUI
but as parameters associated with your program, which you
naturalyy pick up through your GUI.
So at time when you get hold of these parameters you store them in
some object which lives wthin your program
When you ultimately leave your program you make sure you put in some good place this
object amd on start up even before you create
and populate your GUI
you just first check if there is an object stored previous time
These things are indeed more like configuration of your program
and you can store there initial values of yout textFields together
with say preferable paths for writing files.

Have a good evening.

0
 

Author Comment

by:gbcbr
ID: 34992694
Thank you
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
ArrayIndexOutOfBoundException 9 80
oracle 11g 23 79
hibernate example for saving data 19 37
Facing this issue for maven proxy setting 2 9
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question