Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / June 2005

Tip: Looking for answers? Try searching our database.

Text Fields

Thread view: 
aeh - 20 Jun 2005 20:12 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.
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



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.