Java Reference
In-Depth Information
L ISTING 11.2 Continued
Note that the Hyperlink events code (methods removeHyperlinkListener ,
addHyperlinkListener , fireHyperlinkUpdate ) is useful for listening to launch events from
other classes. It could be safely dropped if we use our label only for launching a Web browser.
The most interesting line is probably line 28, in which the browser is pointed to the given URL
using the BasicService JNLP class. This can be as simple as the following line of code:
In order to use it in your code, just set the text to be displayed, like a normal JLabel ,plus the
URL to point to.
This little component could be very handy when used to create professional looking About
dialogs, for instance.
File Management
Handling files with the JNLP API requires the use of the following classes:
FileContents . This class represents a file, both for reading and for writing, using the
usual input and output streams. It is metered; that is, only a given amount of space
(bytes) can be allocated for a file in order to allow JNLP Clients to maintain control on
the local resources allocated to launched applications. Note that path information is
absent. This means that applications obtaining this object (by means of one of the fol-
lowing three services: FileOpenService , FileSaveService and PersistenceService )
can examine only the file contents.
FileOpenService . Applications wanting to access files on the local system should use
this service. For untrusted applications, it is the only way to access local files (which is,
of course, subject to user authorization). This will pop up a File Open dialog box for
choosing a file.
FileSaveService .This class is similar to the FileOpenService, but this time the
JfileChooser dialog box will save a file (represented as a FileContents object).
JNLPRandomAccessFile .The JNLP API implementation of a random access file (a file
treated as an array of bytes).
Search WWH ::

Custom Search