Title: Java Internationalization
ISBN: 0596000197
US Price: $ 39.95

© 2001 O'Reilly & Associates, Inc.

Reviews : Java Books :
Java Internationalization : Isolating Locale-Specific Data With Resource Bundles

Example 4-14 illustrates the power of the ListResourceBundle class. Examples 4-15 and 4-16 show a resource bundle for this applet and the HTML in which the applet is embedded. We display the O'Reilly & Associates logo to the user, but the logo displayed depends on the locale. If the parameter url is set to yes in the applet's HTML file, the logo will contain the URL for that country's O'Reilly website. We don't show all resource bundles for this example because they're so large; instead, we show a relevant portion of the German resource bundle in Example 4-15.

Example 4-14. Applet Used to Display O'Reilly & Associates Logo Depending on the Set Locale

import java. applet.*;
import java. awt.*;
import java. util.*;

public class OReillyLogoApplet extends Applet {
  private ImageArea imageArea;
  private Image logo;
  private Button okButton;
  private ListResourceBundle appletElements;
  private Locale logoAppletLocale;
  private boolean displayURLLogo;
  public void init() {

    // Get the parameters to set the locale for the applet
    logoAppletLocale = new Locale( getParameter(" language"),
        getParameter(" country"));
    if (getParameter(" url") != null &&
        getParameter(" url"). equalsIgnoreCase(" yes"))
      displayURLLogo = true;
    else
      displayURLLogo = false;

    try {
      setLayout( new BorderLayout());
      imageArea = new ImageArea();
      imageArea. setBackground( Color. white);
      imageArea. setSize( getSize(). width, getSize(). height);

      appletElements = (ListResourceBundle) ResourceBundle.
        getBundle(" OReillyResources", logoAppletLocale);
      if (displayURLLogo)
        logo = Toolkit. getDefaultToolkit()
          .createImage(( byte []) appletElements
          .getObject(" OReillyLogoURL"));
      else

        logo = Toolkit. getDefaultToolkit()
          .createImage(( byte []) appletElements
          .getObject(" OReillyLogo"));

      add(" North", imageArea);

      imageArea. displayImage( logo);
    } catch (MissingResourceException e) {
    }
  }
}

class ImageArea extends Canvas {

  Image image;

  public void displayImage( Image image) {
  this. image = image;
  repaint();
  }

  public void paint( Graphics g) {
    if (image != null)
      g. drawImage (image, 0, 0, Color. lightGray, this);
  }
}

Example 4-15. A Partial Listing of the Resource Bundle for Example 4-14 for Germany

import java. util. ListResourceBundle;

public class OReillyResources_ de extends ListResourceBundle {

  public Object [][] getContents() {
    return contents;
  }

  static byte [] OReillyLogo = {
  (byte) 71,
  (byte) 73,
  (byte) 70,
  (byte) 56,
  (byte) 57,
  (byte) 97,
  (byte) 59
  };

  static final Object [][] contents = {
    {" OReillyLogo", OReillyLogo},
    {" OReillyLogoURL", OReillyLogoURL}
  };
}

How to Add Java Applets to Your Site

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.