I am writing a gui and want my program to remember the values that have
been stored in the textfields after the user exits the program so that
when the user restarts the program he does not have to re-type the
data. I am new to using Java and was told that there was a class that
would allow me to do this. Any hints would be appreciated.
Eric Sosman - 20 Jun 2005 20:48 GMT
> I am writing a gui and want my program to remember the values that have
> been stored in the textfields after the user exits the program so that
> when the user restarts the program he does not have to re-type the
> data. I am new to using Java and was told that there was a class that
> would allow me to do this. Any hints would be appreciated.
java.util.Properties may be what you need.

Signature
Eric.Sosman@sun.com
Andrew Thompson - 20 Jun 2005 20:51 GMT
> I am writing a gui and want my program to remember the values that have
> been stored in the textfields after the user exits the program so that
> when the user restarts the program he does not have to re-type the
> data. I am new to using Java and was told that there was a class that
> would allow me to do this. Any hints would be appreciated.
You need Java's I/O functionality. There are a number
of ways (using different classes) you can use.
Check here for a good overview.
<http://java.sun.com/docs/books/tutorial/essential/io/>
.... The following answer is what I put when I thought
you were talking about user program preferences specifically.
It might (or might not) better answer your question.
There are a variety of classes that might be of help.
Is this an application? (unstrusted Applets have security restrictions.)
The easiest is possibly the Preferences[1] class, which
is a Java 1.4+ class to store/retrieve preferences.
I have not had cause to use the preferences API as yet.
[1]
<http://java.sun.com/j2se/1.5.0/docs/api/java/util/prefs/Preferences.html>
There are also other ways to store program preferences.
You can create a custom class that stores the relevant attributes,
then use object serialisation[2] to write it to disk and retrieve it.
If your custom class is also a bean, you can use the
XMLDecoder/Encoder[3] classes introduced in 1.4.
[2] <http://java.sun.com/j2se/1.5.0/docs/guide/serialization/>
[3]
<http://java.sun.com/j2se/1.5.0/docs/api/java/beans/XMLDecoder.html>
<http://java.sun.com/j2se/1.5.0/docs/api/java/beans/XMLEncoder.html>
HTH

Signature
Andrew Thompson
http://www.PhySci.org/codes/ Web & IT Help
http://www.PhySci.org/ Open-source software suite
http://www.1point1C.org/ Science & Technology
http://www.LensEscapes.com/ Images that escape the mundane
Real Gagnon - 21 Jun 2005 01:36 GMT
> I am writing a gui and want my program to remember the values that have
> been stored in the textfields after the user exits the program so that
> when the user restarts the program he does not have to re-type the
> data. I am new to using Java and was told that there was a class that
> would allow me to do this. Any hints would be appreciated.
Look at the java.util.prefs package.
Examples at http://javaalmanac.com/egs/java.util.prefs/pkg.html
Bye.

Signature
Real Gagnon from Quebec, Canada
* Looking for Java or PB code examples ? Visit Real's How-to
* http://www.rgagnon.com/howto.html