Example usage for java.util.prefs Preferences putInt

List of usage examples for java.util.prefs Preferences putInt

Introduction

In this page you can find the example usage for java.util.prefs Preferences putInt.

Prototype

public abstract void putInt(String key, int value);

Source Link

Document

Associates a string representing the specified int value with the specified key in this preference node.

Usage

From source file:Main.java

public static void main(String[] args) throws Exception {
    Preferences prefs = Preferences.userNodeForPackage(Main.class);
    prefs.put("key1", "value1");
    prefs.put("key2", "value2");
    prefs.putInt("intValue", 4);
    prefs.putBoolean("booleanValue", true);
    int usageCount = prefs.getInt("intValue", 0);
    usageCount++;//from   w w w  . j a  v  a  2  s  .  c  om
    prefs.putInt("UsageCount", usageCount);
    Iterator it = Arrays.asList(prefs.keys()).iterator();
    while (it.hasNext()) {
        String key = it.next().toString();
        System.out.println(key + ": " + prefs.get(key, null));
    }
    System.out.println(prefs.getInt("booleanValue", 0));
}

From source file:PlanetPrefs.java

public static void main(String args[]) {
    String names[] = { "Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune", "Pluto" };
    int moons[] = { 0, 0, 1, 2, 16, 18, 21, 8, 1 };

    Preferences prefs = Preferences.userRoot().node("/MasteringJava/Chap17");

    for (int i = 0, n = names.length; i < n; i++) {
        prefs.putInt(names[i], moons[i]);
    }//  ww w  . j a  v  a2  s. c  o m

    try {
        String keys[] = prefs.keys();
        for (int i = 0, n = keys.length; i < n; i++) {
            System.out.println(keys[i] + ": " + prefs.getInt(keys[i], 0));
        }
    } catch (BackingStoreException e) {
        System.err.println("Unable to read backing store: " + e);
    }
}

From source file:MainClass.java

public static void main(String[] args) throws Exception {
    Preferences prefs = Preferences.userNodeForPackage(MainClass.class);
    prefs.put("key1", "value1");
    prefs.put("key2", "value2");
    prefs.putInt("intValue", 4);
    prefs.putBoolean("booleanValue", true);
    int usageCount = prefs.getInt("intValue", 0);
    usageCount++;/* www  .  j  ava2 s . c o  m*/
    prefs.putInt("UsageCount", usageCount);
    Iterator it = Arrays.asList(prefs.keys()).iterator();
    while (it.hasNext()) {
        String key = it.next().toString();
        System.out.println(key + ": " + prefs.get(key, null));
    }
    System.out.println(prefs.getInt("booleanValue", 0));
}

From source file:PreferencesDemo.java

public static void main(String[] args) throws Exception {
    Preferences prefs = Preferences.userNodeForPackage(PreferencesDemo.class);
    prefs.put("Location", "Oz");
    prefs.put("Footwear", "Ruby Slippers");
    prefs.putInt("Companions", 4);
    prefs.putBoolean("Are there witches?", true);
    int usageCount = prefs.getInt("UsageCount", 0);
    usageCount++;/*from w  ww .j  av  a  2s . c  o  m*/
    prefs.putInt("UsageCount", usageCount);
    Iterator it = Arrays.asList(prefs.keys()).iterator();
    while (it.hasNext()) {
        String key = it.next().toString();
        System.out.println(key + ": " + prefs.get(key, null));
    }
    // You must always provide a default value:
    System.out.println("How many companions does Dorothy have? " + prefs.getInt("Companions", 0));
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Preferences prefs = Preferences.userNodeForPackage(String.class);

    // Save some values
    prefs.put("myString", "a string"); // String
    prefs.putBoolean("myBoolean", true); // boolean
    prefs.putInt("myInt", 123); // int
    prefs.putLong("myLong", 123L); // long
    prefs.putFloat("myFloat", 12.3F); // float
    prefs.putDouble("myDouble", 12.3); // double
    byte[] bytes = new byte[10];
    prefs.putByteArray("myByteArray", bytes); // byte[]

    // Export the node to a file
    prefs.exportNode(new FileOutputStream("output.xml"));

}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Preferences prefs = Preferences.userNodeForPackage(String.class);

    // Save some values
    prefs.put("myString", "a string"); // String
    prefs.putBoolean("myBoolean", true); // boolean
    prefs.putInt("myInt", 123); // int
    prefs.putLong("myLong", 123L); // long

    // Save some values in the parent node
    prefs = prefs.parent();//from w  ww.j  av a2  s . c  o  m
    prefs.putFloat("myFloat", 12.3F); // float
    prefs.putDouble("myDouble", 12.3); // double
    byte[] bytes = new byte[10];
    prefs.putByteArray("myByteArray", bytes); // byte[]

    prefs.exportSubtree(new FileOutputStream("output.xml"));
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Preferences prefs = Preferences.userNodeForPackage(Main.class);

    // Preference key name
    final String PREF_NAME = "name_of_preference";

    // Save//from w  w w.  ja va  2  s .c  o m
    prefs.put(PREF_NAME, "a string"); // String
    prefs.putBoolean(PREF_NAME, true); // boolean
    prefs.putInt(PREF_NAME, 123); // int
    prefs.putLong(PREF_NAME, 123L); // long
    prefs.putFloat(PREF_NAME, 12.3F); // float
    prefs.putDouble(PREF_NAME, 12.3); // double
    byte[] bytes = new byte[1024];
    prefs.putByteArray(PREF_NAME, bytes); // byte[]

    // Retrieve
    String s = prefs.get(PREF_NAME, "a string"); // String
    boolean b = prefs.getBoolean(PREF_NAME, true); // boolean
    int i = prefs.getInt(PREF_NAME, 123); // int
    long l = prefs.getLong(PREF_NAME, 123L); // long
    float f = prefs.getFloat(PREF_NAME, 12.3F); // float
    double d = prefs.getDouble(PREF_NAME, 12.3); // double
    bytes = prefs.getByteArray(PREF_NAME, bytes); // byte[]
}

From source file:au.org.ala.delta.editor.EditorPreferences.java

public static void setViewerDividerOffset(int offset) {
    Preferences prefs = Preferences.userNodeForPackage(DeltaEditor.class);
    if (prefs != null) {
        prefs.putInt(VIEWER_DIVIDER_OFFSET_KEY, offset);
    }//from   ww  w  .ja  v  a2s.  c o  m
}

From source file:de.fhg.igd.mapviewer.server.wms.WMSTileConfiguration.java

/**
 * @see WMSConfiguration#saveProperties(Preferences)
 *///from   w  w w  .j  a va 2  s  . co m
@Override
protected void saveProperties(Preferences node) {
    super.saveProperties(node);

    node.putInt(ZOOM_LEVELS, getZoomLevels());
    node.putInt(MIN_TILE_SIZE, getMinTileSize());
    node.putInt(MIN_MAP_SIZE, getMinMapSize());
}

From source file:de.fhg.igd.mapviewer.server.tiles.CustomTileMapServerConfiguration.java

/**
 * Save the configuration's properties to the given preference node
 * /*w  w w . j a  v a2s.c  o m*/
 * @param node the preference node
 */
protected void saveProperties(Preferences node) {
    node.put(URL_PATTERN, getUrlPattern());
    node.putInt(ZOOM_LEVELS, getZoomLevel());
    node.put(ATTRIBUTION, getAttributionText());
}