|
|
Locale-Sensitive Data |
Here's the listing ofNumbersBundle, aListResourceBundlethat contains the data for the GDP, population, and literacy rate.As with the other resource bundles that we've looked at so far,import java.util.ListResourceBundle; public class NumbersBundle extends ListResourceBundle { public Object[][] getContents() { return contents; } static final Object[][] contents = { // LOCALIZE THIS { "GDP", new Double(24700) }, { "Population", new Integer(260713585) }, { "Literacy", new Double(0.97) }, // END "LOCALIZE THIS" }; }NumbersBundleis the default bundle and contains the data for the United States locale. Notice that where the other bundles had strings,NumbersBundlecreatesDoubleandIntegerobjects. Any kind of object can be stored in a resource bundle. To retrieve them, you use thegetObjectmethod provided by theResourceBundleclass. This is the code that LinguaPanel uses to get the GDP, population, and literacy rate fromNumbersBundle:Note that the object returned fromgdp = (Double) numbers.getObject("GDP"); . . . population = (Integer) numbers.getObject("Population"); . . . literacy = (Double) numbers.getObject("Literacy");getObjectis an Object and may need to be cast to the correct type. In the previous example,gdpandliteracyare bothDoubles andpopulationis anInteger. Thus the value returned fromgetObjectis appropriately cast in each statement.The numbers data are displayed next to the text labels in the LinguaPanel. The following is a snapshot of the data for the France locale:
![]()
Here's
NumbersBundle_frwhich contains the data for France:And here'simport java.util.ListResourceBundle; public class NumbersBundle_fr extends ListResourceBundle { public Object[][] getContents() { return contents; } static final Object[][] contents = { // LOCALIZE THIS { "GDP", new Double(18200) }, { "Population", new Integer(57840445) }, { "Literacy", new Double(0.99) }, // END "LOCALIZE THIS" }; }NumbersBundle_en_GBwhich contains the data for the United Kingdom:Using a ListResourceBundle for storing numbers is fairly straightforward. Now, let's look at a more complex example: Using a ListResourceBundle to store sounds.import java.util.ListResourceBundle; public class NumbersBundle_en_GB extends ListResourceBundle { public Object[][] getContents() { return contents; } static final Object[][] contents = { // LOCALIZE THIS { "GDP", new Double(16900) }, { "Population", new Integer(58135110) }, { "Literacy", new Double(0.99) }, // END "LOCALIZE THIS" }; }[PENDING]
|
|
Locale-Sensitive Data |