<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<!--NewPage-->
<html>
<head>
<!-- Generated by javadoc on Wed Jul 28 01:21:15 GMT 1999 -->
<title>
  Class java.util.ResourceBundle
</title>
</head>
<body>
<a name="_top_"></a>
<pre>
<a href="packages.html">All Packages</a>  <a href="tree.html">Class Hierarchy</a>  <a href="Package-java.util.html">This Package</a>  <a href="java.util.Random.html#_top_">Previous</a>  <a href="java.util.SimpleTimeZone.html#_top_">Next</a>  <a href="AllNames.html">Index</a></pre>
<hr>
<h1>
  Class java.util.ResourceBundle
</h1>
<pre>
<a href="java.lang.Object.html#_top_">java.lang.Object</a>
   |
   +----java.util.ResourceBundle
</pre>
<hr>
<dl>
  <dt> public abstract class <b>ResourceBundle</b>
  <dt> extends <a href="java.lang.Object.html#_top_">Object</a>
</dl>
Resource bundles contain locale-specific objects.
 When your program needs a locale-specific resource,
 a <code>String</code> for example, your program can load it
 from the resource bundle that is appropriate for the
 current user's locale. In this way, you can write
 program code that is largely independent of the user's
 locale isolating most, if not all, of the locale-specific
 information in resource bundles.
 <p>
 This allows you to write programs that can:
 <UL type=SQUARE>
 <LI> be easily localized, or translated, into different languages
 <LI> handle multiple locales at once
 <LI> be easily modified later to support even more locales
 </UL>
 <P>
 One resource bundle is, conceptually, a set of related classes that
 inherit from <code>ResourceBundle</code>. Each related subclass of
 <code>ResourceBundle</code> has the same base name plus an additional
 component that identifies its locale. For example, suppose your resource
 bundle is named <code>MyResources</code>. The first class you are likely
 to write is the default resource bundle which simply has the same name as
 its family--<code>MyResources</code>. You can also provide as
 many related locale-specific classes as you need: for example, perhaps
 you would provide a German one named <code>MyResources_de</code>.
 <P>
 Each related subclass of <code>ResourceBundle</code> contains the same
 items, but the items have been translated for the locale represented by that
 <code>ResourceBundle</code> subclass. For example, both <code>MyResources</code>
 and <code>MyResources_de</code> may have a <code>String</code> that's used
 on a button for confirming operations. In <code>MyResources</code> the
 <code>String</code> may contain <code>OK</code> and in
 <code>MyResources_de</code> it may contain <code>Gut</code>.
 <P>
 If there are different resources for different countries, you
 can make specializations: for example, <code>MyResources_de_CH</code>
 for Switzerland. If you want to only modify some of the resources
 in the specialization, you can do so.
 <P>
 When your program needs a locale-specific object, it loads
 the <code>ResourceBundle</code> class using the <code>getBundle</code>
 method:
 <blockquote>
 <pre>
 ResourceBundle myResources =
      ResourceBundle.getBundle("MyResources", currentLocale);
 </pre>
 </blockquote>
 The first argument specifies the family name of the resource
 bundle that contains the object in question. The second argument
 indicates the desired locale. <code>getBundle</code>
 uses these two arguments to construct the name of the
 <code>ResourceBundle</code> subclass it should load as follows.
 <P>
 The resource bundle lookup searches for classes with various suffixes
 on the basis of (1) the desired locale and (2) the default locale (baseclass),
 in the following order from lower-level (more specific) to parent-level
 (less specific):
 <p> baseclass + "_" + language1 + "_" + country1 + "_" + variant1
 <BR> baseclass + "_" + language1 + "_" + country1
 <BR> baseclass + "_" + language1
 <BR> baseclass
 <BR> baseclass + "_" + language2 + "_" + country2 + "_" + variant2
 <BR> baseclass + "_" + language2 + "_" + country2
 <BR> baseclass + "_" + language2
 <P>
 The result of the lookup is a class, but that class may be
 backed by a property file on disk. If a lookup fails,
 <code>getBundle()</code> throws a <code>MissingResourceException</code>.
 <P>
 The baseclass <strong>must</strong> be fully
 qualified (for example, <code>myPackage.MyResources</code>, not just
 <code>MyResources</code>). It must
 also be accessable by your code; it cannot be a class that is private
 to the package where <code>ResourceBundle.getBundle</code> is called.
 <P>
 Note: <code>ResourceBundle</code> are used internally in accessing
 <code>NumberFormat</code>s, <code>Collation</code>s, and so on.
 The lookup strategy is the same.
 <P>
 Resource bundles contain key/value pairs. The keys uniquely
 identify a locale-specific object in the bundle. Here's an
 example of a <code>ListResourceBundle</code> that contains
 two key/value pairs:
 <blockquote>
 <pre>
 class MyResource extends ListResourceBundle {
      public Object[][] getContents() {
              return contents;
      }
      static final Object[][] contents = {
      // LOCALIZE THIS
              {"OkKey", "OK"},
              {"CancelKey", "Cancel"},
      // END OF MATERIAL TO LOCALIZE
      };
 }
 </pre>
 </blockquote>
 Keys are always <code>String</code>s.
 In this example, the keys are <code>OkKey</code> and <code>CancelKey</code>.
 In the above example, the values
 are also <code>String</code>s--<code>OK</code> and <code>Cancel</code>--but
 they don't have to be. The values can be any type of object.
 <P>
 You retrieve an object from resource bundle using the appropriate
 getter method. Because <code>OkKey</code> and <code>CancelKey</code>
 are both strings, you would use <code>getString</code> to retrieve them:
 <blockquote>
 <pre>
 button1 = new Button(myResourceBundle.getString("OkKey"));
 button2 = new Button(myResourceBundle.getString("CancelKey"));
 </pre>
 </blockquote>
 The getter methods all require the key as an argument and return
 the object if found. If the object is not found, the getter method
 throws a <code>MissingResourceException</code>.
 <P>
 Besides <code>getString</code>; ResourceBundle supports a number
 of other methods for getting different types of objects such as
 <code>getStringArray</code>. If you don't have an object that
 matches one of these methods, you can use <code>getObject</code>
 and cast the result to the appropriate type. For example:
 <blockquote>
 <pre>
 int[] myIntegers = (int[]) myResources.getObject("intList");
 </pre>
 </blockquote>
 <P>
 <STRONG>NOTE:</STRONG> You should always supply a baseclass with
 no suffixes. This will be the class of "last resort", if a locale
 is requested that does not exist. For example, below we have a class
 <code>MyResources</code>. It happens to contain US strings,
 so we don't have to have an explicit <code>MyResource_en</code> or
 <code>MyResource_en_US</code>.
 <P>
 The JDK provides two subclasses of <code>ResourceBundle</code>,
 <code>ListResourceBundle</code> and <code>PropertyResourceBundle</code>,
 that provide a fairly simple way to create resources. (Once serialization
 is fully integrated, we will provide another
 way.) As you saw briefly in a prevous example, <code>ListResourceBundle</code>
 manages its resource as a List of key/value pairs.
 <code>PropertyResourceBundle</code> uses a properties file to manage
 its resources.
 <p>
 If <code>ListResourceBundle</code> or <code>PropertyResourceBundle</code>
 do not suit your needs, you can write your own <code>ResourceBundle</code>
 subclass.  Your subclasses must overrde two methods: <code>handleGetObject</code>
 and <code>getKeys()</code>.
 <P>
 The following is a very simple example of a <code>ResourceBundle</code> subclass
 that manages only a few resources (for a larger number of resources
 you would probably use a <code>Hashtable</code>). Notice that if the key
 is not found, <code>handleGetObject</code> must return null. Notice also
 that you don't need to supply a value if a "parent-level"
 <code>ResourceBundle</code> handles the same
 key with the same value (look at uk below).
 <strong><p>Example:</strong>
 <blockquote>
 <pre>
 abstract class MyResources extends ResourceBundle {
     public Object handleGetObject(String key) {
         if (key.equals("okKey")) return "Ok";
         if (key.equals("cancelKey")) return "Cancel";
 	   return null;
     }
 }
 abstract class MyResources_de extends MyResources {
     public Object handleGetObject(String key) {
         if (key.equals("okKey")) return "Gut";
         if (key.equals("cancelKey")) return "Vernichten";
         return null;
     }
 }
 abstract class MyResources_uk extends MyResources {
     public Object handleGetObject(String key) {
         // don't need okKey, since parent level handles it.
         if (key.equals("cancelKey")) return "Dispose";
     	   return null;
     }
 }
 </pre>
 </blockquote>
 You do not have to restrict yourself to using a single family of
 <code>ResourceBundle</code>s. For example, you could have a set of bundles for
 exception messages, <code>ExceptionResources</code>
 (<code>ExceptionResources_fr</code>, <code>ExceptionResources_de</code>, ...),
 and one for widgets, <code>WidgetResource</code> (<code>WidgetResources_fr</code>,
 <code>WidgetResources_de</code>, ...); breaking up the resources however you like.
<p>
<dl>
    <dt> <b>See Also:</b>
    <dd> <a href="java.util.ListResourceBundle.html#_top_">ListResourceBundle</a>, <a href="java.util.PropertyResourceBundle.html#_top_">PropertyResourceBundle</a>, <a href="java.util.MissingResourceException.html#_top_">MissingResourceException</a>
</dl>
<hr>
<a name="index"></a>
<h2>
  <img src="images/variable-index.gif" width=207 height=38 alt="Variable Index">
</h2>
<dl>
  <dt> <img src="images/magenta-ball-small.gif" width=6 height=6 alt=" o ">
	<a href="#parent"><b>parent</b></a>
  <dd>  The parent bundle is consulted by getObject when this bundle
 does not contain a particular resource.
</dl>
<h2>
  <img src="images/constructor-index.gif" width=275 height=38 alt="Constructor Index">
</h2>
<dl>
  <dt> <img src="images/yellow-ball-small.gif" width=6 height=6 alt=" o ">
	<a href="#ResourceBundle()"><b>ResourceBundle</b></a>()
  <dd> 
</dl>
<h2>
  <img src="images/method-index.gif" width=207 height=38 alt="Method Index">
</h2>
<dl>
  <dt> <img src="images/green-ball-small.gif" width=6 height=6 alt=" o ">
	<a href="#getBundle(java.lang.String)"><b>getBundle</b></a>(String)
  <dd>  Get the appropriate ResourceBundle subclass.
  <dt> <img src="images/green-ball-small.gif" width=6 height=6 alt=" o ">
	<a href="#getBundle(java.lang.String, java.util.Locale)"><b>getBundle</b></a>(String, Locale)
  <dd>  Get the appropriate ResourceBundle subclass.
  <dt> <img src="images/red-ball-small.gif" width=6 height=6 alt=" o ">
	<a href="#getKeys()"><b>getKeys</b></a>()
  <dd>  Return an enumeration of the keys.
  <dt> <img src="images/red-ball-small.gif" width=6 height=6 alt=" o ">
	<a href="#getObject(java.lang.String)"><b>getObject</b></a>(String)
  <dd>  Get an object from a ResourceBundle.
  <dt> <img src="images/red-ball-small.gif" width=6 height=6 alt=" o ">
	<a href="#getString(java.lang.String)"><b>getString</b></a>(String)
  <dd>  Get an object from a ResourceBundle.
  <dt> <img src="images/red-ball-small.gif" width=6 height=6 alt=" o ">
	<a href="#getStringArray(java.lang.String)"><b>getStringArray</b></a>(String)
  <dd>  Get an object from a ResourceBundle.
  <dt> <img src="images/red-ball-small.gif" width=6 height=6 alt=" o ">
	<a href="#handleGetObject(java.lang.String)"><b>handleGetObject</b></a>(String)
  <dd> Get an object from a ResourceBundle.
  <dt> <img src="images/red-ball-small.gif" width=6 height=6 alt=" o ">
	<a href="#setParent(java.util.ResourceBundle)"><b>setParent</b></a>(ResourceBundle)
  <dd>  Set the parent bundle of this bundle.
</dl>
<a name="variables"></a>
<h2>
  <img src="images/variables.gif" width=153 height=38 alt="Variables">
</h2>
<a name="parent"><img src="images/magenta-ball.gif" width=12 height=12 alt=" o "></a>
<b>parent</b>
<pre>
 protected <a href="#_top_">ResourceBundle</a> parent
</pre>
<dl>
  <dd> The parent bundle is consulted by getObject when this bundle
 does not contain a particular resource.<p>
</dl>
<a name="constructors"></a>
<h2>
  <img src="images/constructors.gif" width=231 height=38 alt="Constructors">
</h2>
<a name="ResourceBundle"></a>
<a name="ResourceBundle()"><img src="images/yellow-ball.gif" width=12 height=12 alt=" o "></a>
<b>ResourceBundle</b>
<pre>
 public ResourceBundle()
</pre>
<a name="methods"></a>
<h2>
  <img src="images/methods.gif" width=151 height=38 alt="Methods">
</h2>
<a name="getString(java.lang.String)"><img src="images/red-ball.gif" width=12 height=12 alt=" o "></a>
<a name="getString"><b>getString</b></a>
<pre>
 public final <a href="java.lang.String.html#_top_">String</a> getString(<a href="java.lang.String.html#_top_">String</a> key) throws <a href="java.util.MissingResourceException.html#_top_">MissingResourceException</a>
</pre>
<dl>
  <dd> Get an object from a ResourceBundle.
 <BR>Convenience method to save casting.
<p>
  <dd><dl>
    <dt> <b>Parameters:</b>
    <dd> key - see class description.
  </dl></dd>
</dl>
<a name="getStringArray(java.lang.String)"><img src="images/red-ball.gif" width=12 height=12 alt=" o "></a>
<a name="getStringArray"><b>getStringArray</b></a>
<pre>
 public final <a href="java.lang.String.html#_top_">String</a>[] getStringArray(<a href="java.lang.String.html#_top_">String</a> key) throws <a href="java.util.MissingResourceException.html#_top_">MissingResourceException</a>
</pre>
<dl>
  <dd> Get an object from a ResourceBundle.
 <BR>Convenience method to save casting.
<p>
  <dd><dl>
    <dt> <b>Parameters:</b>
    <dd> key - see class description.
  </dl></dd>
</dl>
<a name="getObject(java.lang.String)"><img src="images/red-ball.gif" width=12 height=12 alt=" o "></a>
<a name="getObject"><b>getObject</b></a>
<pre>
 public final <a href="java.lang.Object.html#_top_">Object</a> getObject(<a href="java.lang.String.html#_top_">String</a> key) throws <a href="java.util.MissingResourceException.html#_top_">MissingResourceException</a>
</pre>
<dl>
  <dd> Get an object from a ResourceBundle.
<p>
  <dd><dl>
    <dt> <b>Parameters:</b>
    <dd> key - see class description.
  </dl></dd>
</dl>
<a name="getBundle(java.lang.String)"><img src="images/green-ball.gif" width=12 height=12 alt=" o "></a>
<a name="getBundle"><b>getBundle</b></a>
<pre>
 public static final <a href="#_top_">ResourceBundle</a> getBundle(<a href="java.lang.String.html#_top_">String</a> baseName) throws <a href="java.util.MissingResourceException.html#_top_">MissingResourceException</a>
</pre>
<dl>
  <dd> Get the appropriate ResourceBundle subclass.
<p>
  <dd><dl>
    <dt> <b>Parameters:</b>
    <dd> baseName - see class description.
  </dl></dd>
</dl>
<a name="getBundle(java.lang.String, java.util.Locale)"><img src="images/green-ball.gif" width=12 height=12 alt=" o "></a>
<a name="getBundle"><b>getBundle</b></a>
<pre>
 public static final <a href="#_top_">ResourceBundle</a> getBundle(<a href="java.lang.String.html#_top_">String</a> baseName,
                                              <a href="java.util.Locale.html#_top_">Locale</a> locale)
</pre>
<dl>
  <dd> Get the appropriate ResourceBundle subclass.
<p>
  <dd><dl>
    <dt> <b>Parameters:</b>
    <dd> baseName - see class description.
    <dd> locale - see class description.
  </dl></dd>
</dl>
<a name="setParent(java.util.ResourceBundle)"><img src="images/red-ball.gif" width=12 height=12 alt=" o "></a>
<a name="setParent"><b>setParent</b></a>
<pre>
 protected void setParent(<a href="#_top_">ResourceBundle</a> parent)
</pre>
<dl>
  <dd> Set the parent bundle of this bundle.  The parent bundle is
 searched by getObject when this bundle does not contain a
 particular resource.
<p>
  <dd><dl>
    <dt> <b>Parameters:</b>
    <dd> parent - this bundle's parent bundle.
  </dl></dd>
</dl>
<a name="handleGetObject(java.lang.String)"><img src="images/red-ball.gif" width=12 height=12 alt=" o "></a>
<a name="handleGetObject"><b>handleGetObject</b></a>
<pre>
 protected abstract <a href="java.lang.Object.html#_top_">Object</a> handleGetObject(<a href="java.lang.String.html#_top_">String</a> key) throws <a href="java.util.MissingResourceException.html#_top_">MissingResourceException</a>
</pre>
<dl>
  <dd> Get an object from a ResourceBundle.
 <STRONG>NOTE: </STRONG>Subclasses must override.
<p>
  <dd><dl>
    <dt> <b>Parameters:</b>
    <dd> key - see class description.
  </dl></dd>
</dl>
<a name="getKeys()"><img src="images/red-ball.gif" width=12 height=12 alt=" o "></a>
<a name="getKeys"><b>getKeys</b></a>
<pre>
 public abstract <a href="java.util.Enumeration.html#_top_">Enumeration</a> getKeys()
</pre>
<dl>
  <dd> Return an enumeration of the keys.
 <STRONG>NOTE: </STRONG>Subclasses must override.
<p>
</dl>
<hr>
<pre>
<a href="packages.html">All Packages</a>  <a href="tree.html">Class Hierarchy</a>  <a href="Package-java.util.html">This Package</a>  <a href="java.util.Random.html#_top_">Previous</a>  <a href="java.util.SimpleTimeZone.html#_top_">Next</a>  <a href="AllNames.html">Index</a></pre>
</body>
</html>
