Created
January 27, 2013 19:53
-
-
Save moomoohk/4650110 to your computer and use it in GitHub Desktop.
My config class. Uses Java properties instead of XML. Works fine when bundled in a JAR and run in the OS (as opposed to being run in the IDE). I made it a while ago so I don't really remember how everything works, or how efficient it is...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.moomoohk.ThreeD; | |
import java.util.prefs.Preferences; | |
public class Config | |
{ | |
public static Preferences prefs = Preferences.userNodeForPackage(Config.class); | |
public void save(String key, int val) | |
{ | |
System.out.println("Saving " + val + " to " + key); | |
int def = 0; | |
if (key.equalsIgnoreCase("width")) | |
def = 800; | |
if (key.equalsIgnoreCase("height")) | |
def = 600; | |
prefs.putInt(key, val); | |
System.out.println("Saved " + prefs.getInt(key, def) + " to " + key); | |
} | |
public void loadDimensions() | |
{ | |
Preferences prefs = Preferences.userNodeForPackage(getClass()); | |
int w = prefs.getInt("Width", 800); | |
int h = prefs.getInt("Height", 600); | |
setRes(w, h); | |
} | |
public int getSel() | |
{ | |
Preferences prefs = Preferences.userNodeForPackage(getClass()); | |
int w = prefs.getInt("Width", 800); | |
if (w == 640) | |
return 1; | |
if (w == 800) | |
return 2; | |
return 3; | |
} | |
public void setRes(int width, int height) | |
{ | |
Display.dim.height = height; | |
Display.dim.width = width; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment