You can change the value in the language parameter in HTML to see a different
logo displayed in the applet, as shown in Example 4-16. If the value for the url
parameter is not yes, no URL is displayed in the logo. For example, to create Figure
4-3, set the language parameter to fr and the url parameter to no. To create
Figure 4-4, set the language parameter to de and the url parameter to yes.
Figures 4-3 and 4-4 show the applet running in the French language (no URL) and
the German language (with URL), respectively.
Figure 4-3. Logo applet using French language (no URL)
Figure 4-4. Logo applet using German language (with URL)
Example 4-16. HTML Used to Run the O'Reilly Logo Display Applet
<HTML>
<HEAD>
<TITLE> O'Reilly Logo Applet</ TITLE>
</ HEAD>
<BODY>
<APPLET CODE=" OReillyLogoApplet" WIDTH= 270 HEIGHT= 115>
<PARAM NAME=" country" VALUE="">
<PARAM NAME=" language" VALUE=" fr">
<PARAM NAME=" url" VALUE=" yes">
</ APPLET>
</ BODY>
</ HTML>
Example 4-17 shows a utility we've used in this chapter to create a
ListResourceBundle class automatically, using data from an image or a sound file.
You can use any data file you like. You'll find that adding this type of data to your
resource bundles, specifying each byte manually, is very time consuming! This
program takes three arguments: the data file to include in the resource bundle;
the key used to retrieve the resource from the bundle; and the name of the class
you subclass from ListResourceBundle. Specify the class name with no .java
extension. The proper .java source file is created from the name you supply.
Here's how you might use this utility:
C:\> java ListResourceBundleCreator oreilly_ logo_ germany. gif
OReillyLogoGerman
OReillyLogoResources_ de
Example 4-17. Utility Program to Create a ListResourceBundle Using Data from a User-Supplied Data File
import java. io.*;
import java. util. Vector;
public class ListResourceBundleCreator {
public static void main( String [] argv) throws Exception{
FileInputStream inputFileReader = new FileInputStream( argv[ 0]);
DataInputStream dis = new DataInputStream( inputFileReader);
long fileSize;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Vector myVector = new Vector();
while (true) {
try {
myVector. addElement( new Integer( dis. readUnsignedByte()));
} catch (EOFException e) {
break;
}
}
fileSize = myVector. size();
FileWriter outputFileWriter = new FileWriter( argv[ 2] + ". java");
outputFileWriter. write(" import java. util.
ListResourceBundle;\ n\ n");
outputFileWriter. write(" public class " + argv[ 2] +
" extends ListResourceBundle {\ n\ n");
outputFileWriter. write(" public Object [][] getContents() {\ n");
outputFileWriter. write(" return contents;\ n");
outputFileWriter. write(" }\ n\ n");
outputFileWriter. write(" static byte [] " + argv[ 1] + " = {\ n");
for (int i = 0; i < fileSize; i++) {
outputFileWriter. write("\ t( byte)");
outputFileWriter. write((( Integer) myVector.
elementAt( i)). toString());
if (i < fileSize -1)
outputFileWriter. write(",\ n");
}
outputFileWriter. write("\ n\ t};\ n\ n");
outputFileWriter. write(" static final Object [][] contents = {\ n");
outputFileWriter. write(" {\"" + argv[ 1] + "\", " +
argv[ 1] + "}\ n");
outputFileWriter. write(" };\ n");
outputFileWriter. write("}\ n");
outputFileWriter. close();
}
}
[Lines 24 and 25 above are one line, as are lines 35-36 and 41-42. They have been split for formatting purposes.]
New on the Java Boutique:
New Review:
Time Management Made Easy with the Quartz Enterprise Job Scheduler
Why not just use the Java timer API? This open source scheduling
API boasts simplicity, ease-of-integration, a well-rounded feature
set, and it's free!
New Applet:
Reverse Complement
Reverse Complement is a simple applet that converts DNA or RNA
sequences into three useful formats.
Elsewhere on internet.com:
WebDeveloper Java
Lots of Java information on webdeveloper.com
WDVL Java
Thorough Java resource at the Web Developer's Virtual Library.
ScriptSearch Java
Hundreds of free Java code files to download.
jGuru: Your View of the Java Universe
Customizable portal with online training, FAQs, regular news updates, and tutorials.