Java Technology Home Page
A-Z Index

Java Developer Connection(SM)
Online Training

Downloads, APIs, Documentation
Java Developer Connection
Tutorials, Tech Articles, Training
Online Support
Community Discussion
News & Events from Everywhere
Products from Everywhere
How Java Technology is Used Worldwide
 
Training Index

JavaBeansTM Short Course
Getting Resources with Clara Barton

By MageLang Institute

[Tutorial Contents]
[Behavior] [Help] [API Docs] [Solution]

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:

  1. Find the resource file 'Barton.resources' and open an InputStream to it.

  2. Load the properties.

  3. Get the 'message.font' property. If not found, use the default fontDefault. Once acquired, decode it into a Font.

  4. Get the 'message.text' property. If not found, use the default msgDefault. This provides a short text message/slogan to display.

  5. 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.

  6. 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.

  7. 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.

[ This page was updated: 9-Nov-99 ]

Products & APIs | Developer Connection | Docs & Training | Online Support
Community Discussion | Industry News | Solutions Marketplace | Case Studies
Glossary - Applets - Tutorial - Employment - Business & Licensing - Java Store - Java in the Real World
FAQ | Feedback | Map | A-Z Index
For more information on Java technology
and other software from Sun Microsystems, call:
(800) 786-7638
Outside the U.S. and Canada, dial your country's AT&T Direct Access Number first.
Sun Microsystems, Inc.
Copyright © 1995-99 Sun Microsystems, Inc.
All Rights Reserved. Legal Terms. Privacy Policy.