![]()
(chat, newsreader, calendar)
|
![]() |
|
|
|
Course Notes Table of Contents Exercises | Online Training Index
|
|
Help: Getting Resources with Clara Barton
MageLang Institute
|
|
Help is available for each task, or you can go straight to
the solution source code.
The Class.getResourceAsStream will suffice in doing this. InputStream is = getClass().getResourceAsStream( "Barton.resources"); Task 2Load the properties.Use the Property.load method to load them from the InputStream. p.load (is);A property list is a set of key-value pairs. When you ask about the contents of a key (Property.getProperty), it returns its value (if it exists). This exercise can use three. For example:
Task 3Get the 'message.font' property. If not found, use the default fontDefault. Once acquired, decode it into a Font.Use the Property.getProperty method to find the value. Use the Font.decode method to convert the text string into a Font.
f = Font.decode(
p.getProperty("message.font", fontDefault));
Task 4Get the 'message.text' property. If not found, use the default msgDefault. This provides a short text message/slogan to display.
msg = p.getProperty ("message.text", msgDefault);
Task 5Get 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.Use Property.getProperty to get the name of the image resource file. Use Class.getResource to get the resource as a URL. Use Toolkit.getImage to get the image.
String imageFile = p.getProperty ("image.file");
URL url = getClass().getResource (imageFile);
im = getToolkit().getImage (url);
Task 6Compile 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.javac Barton.java java Barton Task 7Place 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.
|
|
Copyright © 1997 MageLang Institute. All Rights Reserved May-97 Copyright © 1996, 1997 Sun Microsystems Inc. All Rights Reserved |