Java Reference
In-Depth Information
Example 10•22: GUIResourceBundle.java (continued)
}
}
/** Return a resource of type double */
public double getDouble(String key) throws MissingResourceException {
String s = bundle.getString(key);
try {
return Double.parseDouble(s);
} catch (NumberFormatException e) {
throw new MalformedResourceException("double", key);
}
}
/** As above, but with a default value */
public double getDouble(String key, double defaultValue) {
try { return getDouble(key); }
catch(MissingResourceException e) {
if (e instanceof MalformedResourceException)
System.err.println("WARNING: " + e.getMessage());
return defaultValue;
}
}
/** Look up the named resource and convert to a Font */
public Font getFont(String key) throws MissingResourceException {
// Font.decode() always returns a Font object, so we can't check
// whether the resource value was well-formed or not.
return Font.decode(bundle.getString(key));
}
/** As above, but with a default value */
public Font getFont(String key, Font defaultValue) {
try { return getFont(key); }
catch (MissingResourceException e) { return defaultValue; }
}
/** Look up the named resource, and convert to a Color */
public Color getColor(String key) throws MissingResourceException {
try {
return Color.decode(bundle.getString(key));
}
catch (NumberFormatException e) {
// It would be useful to try to parse color names here as well
// as numeric color specifications
throw new MalformedResourceException("Color", key);
}
}
/** As above, but with a default value */
public Color getColor(String key, Color defaultValue) {
try { return getColor(key); }
catch(MissingResourceException e) {
if (e instanceof MalformedResourceException)
System.err.println("WARNING: " + e.getMessage());
return defaultValue;
}
}
Search WWH ::




Custom Search