Java Reference
In-Depth Information
L ISTING 11.1 Continued
}
public static Utilities getInstance(){
if (util==null)
util = new Utilities();
return util;
}
public static Utilities getInstance(String resourceBundleName){
bundleFilename = resourceBundleName;
if (util==null)
getInstance();
else
System.out.println(
util.getClass()+” getInstance must be invoked as initializator.”);
return util;
}
}
This class provides several services added on top of the JNLP API:
• Robust resources retrieval. For icons and resource bundles, if the given item is not found,
a default value is always returned. For messages, an empty string is returned in case of a
missing value.
•For icons, a default icon is always provided by creating it in code, so that
NullPointerException messages for inexistent icons are never thrown. See lines 18-19
and the initializeDefaultResources method at lines 34-38.
•It saves programmers from lengthy try-catch constructs in standard services creation code.
Note also that an instance of the BasicService class is always created because it is usu-
ally the most often used service.
The Utilities class has been kept simple to serve a didactic purpose as well. You can always
expand it as needed.
A Hypertext Swing Label Class
To see a simple and interesting example of how it is possible to take advantage of the JNLP
Client API and the Utilities class, let's use a very simple Jlabel component that can be
clicked just like a hyperlink in a Web page. When this action is completed, a Web browser will
open, pointing to the given URL. Listing 11.2 shows the code.
Search WWH ::




Custom Search