Java Reference
In-Depth Information
Obtaining Xlet Properties and Resources
As you saw in the section “Using the Xlet Context” in this chapter, the XletContext
provided by the application runtime to your Xlet includes the getXletProperty method
for obtaining runtime properties. The only property presently defined by the Java ME
standard itself is the XletContext.ARGS property, which permits your application to col-
lect any command-line launch arguments passed when the user launched your
application, letting the application manager pass options to your Xlet.
The Xlet can also interrogate the system for properties using the static class
method System.getProperty , which typically returns system-level properties proprietary
to the platform, rather than runtime properties defined by the PBP or PP implementa-
tion on which your application is running. For Java ME consumer devices aimed at the
audio-visual market, for example, these include information about the file system, the
broadcast profile, the availability of Internet access, and the version number of addi-
tional packages such as the UI widget set (for example, the HAVi package).
Xlets are typically packaged as JAR files, so you can include additional resources
with your application as part of the associated JAR file. To access other resources in
your Xlet's JAR file, your implementation must use the Xlet context's class loader, just as
it would for a stand-alone application or applet. For example, you might write the code
shown in Listing 9-6.
Listing 9-6. Accessing an Image from an Xlet JAR File
ClassLoader cl = context.getClassLoader();
Icon icon = new ImageIcon(cl.getResource("images/icon.png"));
Using the class loader provided by the XletContext , you can get application and
system resources by name, and you can obtain either a URL to the resource or an
InputStream to the resource using one of the following methods:
getResource : Returns a URL to the named resource
getResourceAsStream : Returns an InputStream to the named resource
getSystemResource : Returns a URL to the named system resource, which is a
platform-specific attribute of the target hardware
getSystemResourceAsStream : Returns an InputStream to the named system resource,
which is a platform-specific attribute of the target hardware
 
Search WWH ::




Custom Search