I am currently writing a game, and have come to the point where I need the user to be able to save preferences for things such as the JFrame size, key bindings etc. The users will be running the game through a jar downloaded from my website.
I've decided to go with the Preferences API under "java.util.prefs.Preferences". I am still quite new when it comes to reading things like documentation, and would like someone to help explain a bit to me.
So far, I have something like this:
Preferences prefs = Preferences.userNodeForPackage(com.custardgames.horde2d.Game.class);
prefs.put(name, value);
Now then, how do I actually get to saving the preference file on the users computer? Right now, if I run the program again and try just:
Preferences prefs = Preferences.userNodeForPackage(com.custardgames.horde2d.Game.class);
System.out.println(prefs.get(name, null));
It just returns null which is the default value if there is nothing saved. I know I am missing the vital part of actually saving the file, and then opening it the correct way, but haven't gotten much out of googling it.
Thanks so much in advance!
Edit: FYI, for reading images, I am using something like this:
BufferedImage currentImage=ImageIO.read(this.getClass().getClassLoader().getResource("res/images/image.jpg"));
I would like to be able to do something similar with preferences.
Edit:
name
and value
are both String variables declared beforehand.