Java Reference
In-Depth Information
getDisplayCountry() expects a Locale argument and displays the country
name in the language of the specified locale.
Write a program that displays the country names for all locales returned by
NumberFormat.getAvailableLocales() . Using the static locale constants
defined by the Locale class, display each country name in English, French,
German, and Italian.
7-2. Modify the Portfolio class of Example 7-3 to remove all hardcoded display
strings. Instead, use the ResourceBundle and MessageFormat classes as
demonstrated in Example 7-4 and Example 7-5.
7-3. Write a multicity digital clock program that displays the current date and time
in the cities Washington, London, Paris, Bonn, Beijing, and Tokyo. Display the
dates and times using the customary formats for those cities. You'll want to
read about the java.util.TimeZone class and the DateFormat.setTimeZone()
method. Consult a map or search the Internet to determine the time zones for
each of the cities. Write the program as an AWT or Swing application or as an
applet after you have read Chapter 10 and Chapter 15, Applets . You may want
to base the program on the Clock applet from Example 15-2.
7-4. Example 7-4 shows how you can use a ResourceBundle to internationalize
the text that appears within menus in your application. One feature of Swing
that discourages internationalization is that the JButton , JMenu , and JMenuItem
constructors, among others, are passed the labels they are to display. This
makes it very tempting for programmers to hardcode these labels into their
programs. Create internationalized subclasses of these components, named
IButton , IMenu , and IMenuItem , that instead take resource names as their con-
structor arguments. Each class should look up a resource bundle named
“Labels” and use this bundle to look up the button or menu label that corre-
sponds to the resource name passed to the constructor. If the bundle does
not exist, or if a given resource is not defined in it, the IButton , IMenu , and
IMenuItem classes should default to using the resource names as their labels.
Write a simple test program (and some test property files) that demonstrate
these new classes under two or three different locales. You'll probably want
to read Chapter 10 before working on this exercise.
Search WWH ::




Custom Search