[英]Java and jtextfield value
I have jTextFields
. 我有
jTextFields
。 If the user type tHe AET , the HOST and the PORT NUMBER in them, I need to save that permanently when he clicks on the save button. 如果用户在其中键入AET,主机和端口号,我需要在他单击保存按钮时将其永久保存。 How can I do that with Java to display the values automatically every time I run my application?
我该如何使用Java来在每次运行应用程序时自动显示值?
You have many options. 您有很多选择。
You could save to a file . 您可以保存到文件 。
PrintWriter pw = new PrintWriter(new File('myFile.txt'));
pw.printLine(textField.getText());
to read from file would be.... 从文件读取将是...。
try (BufferedReader br = new BufferedReader(new FileReader(file))) {
String line;
while ((line = br.readLine()) != null) {
// process the line.
}
}
More information on files here 有关文件的更多信息,请点击此处
you could save to the users registry . 您可以保存到用户注册表 。
Preferences userPref = Preferences.userRoot();
userPref.put('textFieldKey', textField.getText());
to read from registry would be.... 从注册表中读取将是...。
Preferences userPref = Preferences.userRoot();
userPref.get('textFieldKey', 'defaultValue');
More information on preferences/registry storage here 有关首选项/注册表存储的更多信息,请参见 此处
You could also save to a DB but this would require SQL knowledge. 您也可以保存到数据库,但这需要SQL知识。
There is also the option of using serialization please see an example here 还有使用序列化的选项,请在此处查看示例
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.