views:

40

answers:

3

For example, I have a window with a preference button. I want to make it so that when user press the preference button and checks his/her appropriate options and press ok, it saves the preference, then when user presses run on the main window, it runs accordingly to preference the user changed on the preference window.

Thank you in advance.

+2  A: 

There is a Java Preferences API specifically for this purpose. It lets you store per-user preferences in an easy cross-platform way, while the API itself takes care of where and how to store the data.

casablanca
+3  A: 

You can use java.util.prefs package. A simple example:

// Retrieve the user preference node for the package com.mycompany
Preferences prefs = Preferences.userNodeForPackage(com.mycompany.MyClass.class);

// Preference key name
final String PREF_NAME = "name_of_preference";

// Set the value of the preference
String newValue = "a string";
prefs.put(PREF_NAME, newValue);

// Get the value of the preference;
// default value is returned if the preference does not exist
String defaultValue = "default string";
String propertyValue = prefs.get(PREF_NAME, defaultValue); // "a string"

There are many more examples at Eample Depot.

Peter Knego
Thank you!~ Thanks to others as well I didn't know who to give credits to ^^
js0823
A: 

Besides Preferences, there is another alternative available for rich clients launched using Java Web Start. This alternative is the PersistenceService. Here is a small demo. of the PersistenceService.

It is also a service where the programmer does not need to worry about the details of where the information is stored.

Andrew Thompson