例如,我有一个带有首选项按钮的窗口。 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窗口。
提前谢谢你。
最佳答案
您可以使用 java.util.prefs包裹。一个简单的例子:
// 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"
还有更多 examples at java2s.com .
关于java - 如何在 Java 中保存首选项用户设置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4017137/