Follow along with the video below to see how to install our site as a web app on your home screen.
Anmerkung: This feature may not be available in some browsers.
Ja, ich möchte Benutzerdaten und Spielstand speichern.Ja, Resourcen innerhalb der Jar kann man nicht verändern.
Was willst du denn erreichen, Benutzereinstellungen oä speichern?
// This will define a node in which the preferences can be stored
prefs = Preferences.userRoot().node(this.getClass().getName());
String ID1 = "Test1";
String ID2 = "Test2";
String ID3 = "Test3";
// First we will get the values
// Define a boolean value
System.out.println(prefs.getBoolean(ID1, true));
// Define a string with default "Hello World
System.out.println(prefs.get(ID2, "Hello World"));
// Define a integer with default 50
System.out.println(prefs.getInt(ID3, 50));
// now set the values
prefs.putBoolean(ID1, false);
prefs.put(ID2, "Hello Europa");
prefs.putInt(ID3, 45);
// Delete the preference settings for the first value
prefs.remove(ID1);
Danke, das werde ich mal versuchen.Du kannst die Default-Einstellungen ohne weiteres in dem JAR-File ablegen. Einstellungen die der Nutzer dann ändert, kannst du z.B.: mit der
Preferences API https://docs.oracle.com/javase/8/docs/technotes/guides/preferences/overview.html speichern.
Java:// This will define a node in which the preferences can be stored prefs = Preferences.userRoot().node(this.getClass().getName()); String ID1 = "Test1"; String ID2 = "Test2"; String ID3 = "Test3"; // First we will get the values // Define a boolean value System.out.println(prefs.getBoolean(ID1, true)); // Define a string with default "Hello World System.out.println(prefs.get(ID2, "Hello World")); // Define a integer with default 50 System.out.println(prefs.getInt(ID3, 50)); // now set the values prefs.putBoolean(ID1, false); prefs.put(ID2, "Hello Europa"); prefs.putInt(ID3, 45); // Delete the preference settings for the first value prefs.remove(ID1);
Ok, das funktioniert. Allerdings bekomme ich die Warnung:Du kannst die Default-Einstellungen ohne weiteres in dem JAR-File ablegen. Einstellungen die der Nutzer dann ändert, kannst du z.B.: mit der
Preferences API https://docs.oracle.com/javase/8/docs/technotes/guides/preferences/overview.html speichern.
Java:// This will define a node in which the preferences can be stored prefs = Preferences.userRoot().node(this.getClass().getName()); String ID1 = "Test1"; String ID2 = "Test2"; String ID3 = "Test3"; // First we will get the values // Define a boolean value System.out.println(prefs.getBoolean(ID1, true)); // Define a string with default "Hello World System.out.println(prefs.get(ID2, "Hello World")); // Define a integer with default 50 System.out.println(prefs.getInt(ID3, 50)); // now set the values prefs.putBoolean(ID1, false); prefs.put(ID2, "Hello Europa"); prefs.putInt(ID3, 45); // Delete the preference settings for the first value prefs.remove(ID1);
Preferences prefs = Preferences.userNodeForPackage(Gadget.class);