Here you can find the source of getRectangle(Properties prop, final String key, final Rectangle def)
Parameter | Description |
---|---|
prop | The Properties set |
key | the key used to store this property |
def | a default in case the property cannot be retrieved |
public static Rectangle getRectangle(Properties prop, final String key, final Rectangle def)
//package com.java2s; import java.awt.Rectangle; import java.util.Properties; public class Main { /**//from w w w . ja v a 2 s . c o m * @param prop The Properties set * @param key the key used to store this property * @param def a default in case the property cannot be retrieved */ public static Rectangle getRectangle(Properties prop, final String key, final Rectangle def) { try { final Rectangle result = new Rectangle(); result.x = getInteger(prop, key.concat("-x")); result.y = getInteger(prop, key.concat("-y")); result.width = getInteger(prop, key.concat("-w")); result.height = getInteger(prop, key.concat("-h")); return result; } catch (Exception e) { return def; } } /** * @exception NumberFormatException if the property retrieved cannot be converted to <code>int</code> * @param prop The Properties set * @param key the key used to store this property */ public static int getInteger(Properties prop, final String key) throws NumberFormatException { return Integer.parseInt(prop.getProperty(key)); } /** * @param prop The Properties set * @param key the key used to store this property * @param def a default in case the property cannot be retrieved */ public static int getInteger(Properties prop, final String key, final int def) { try { final String s = prop.getProperty(key); return s == null ? def : Integer.parseInt(s); } catch (Exception e) { return def; } } }