Skeleton Code
Called the Angel of the Battlefield, Clara Barton set up a supply service during the Civil War,
was a nurse on battlefields, and led searches for the missing.
After working behind German lines for the International Red Cross in the Franco-Prussian War,
Clara Barton organized (1881) the American Red Cross, which she headed until 1904.
With applets, you can use getCodeBase
, getDocumentBase
, and getParameter
to
get support files or run-time settings. Since Beans are stand-along components, where would you locate an
image or sound file for it to use? Beans use
Java resource files.
The support file or information can be provided within the Bean's .jar
file or can be located locally within the user's CLASSPATH
.
The use of resource files is not restricted to use with JavaBeans. In fact, this
exercise creates an application that relies on a resource file that is a
property list (see the online documentation for a complete description of
Property
).
Perform the following tasks:
Find the resource file 'Barton.resources
' and open an InputStream
to it.
Load the properties.
Get the 'message.font
' property. If not found, use the default fontDefault
.
Once acquired, decode it into a Font
.
Get the 'message.text
' property. If not found, use the default msgDefault
.
This provides a short text message/slogan to display.
Get the 'image.file
' property. This provides the name of a file to display.
Find the resource file specified as the property and load the image.
Compile and run the Barton
program. All the work to display
everything has been done for you. Since there is no resource file yet, all
the default behavior will be used.
Place the Barton.resources file in the current
directory, or somewhere in your CLASSPATH. Make sure the
redcross.gif file is also in the current directory,
or somewhere in your CLASSPATH. Then, rerun the program.
When dealing with resources, the system returns a
URL
or an
InputStream
that could be used
for anything, not just a property list or image file, like this exercise.
The task numbers above are linked to the
step-by-step help page. Also available
is a complete solution to the
problem, and expected behavior,
to demonstrate it.
Copyright © 1997 MageLang Institute. All Rights Reserved.