ListResourceBundle

ListResourceBundle
    ListResourceBundle  是  ResourceBundle  的一个抽象类,用于管理方便而又易于使用的列表中的语言环境资源。有关资源包的常规信息,请参阅  ResourceBundle
    
子类必须重写  getContents 并提供一个数组,其中数组中的每个项都是一个对象对。每对的第一个元素是键,该键必须是一个  String,并且第二个元素是和该键相关联的值。
       下面的 示例 显示了具有基本名称 "MyResources" 的资源包系列的两个成员。"MyResources" 是资源包系列的默认成员,"MyResources_fr" 是 French 成员。这些成员是基于 ListResourceBundle (一个相关的 示例 显示了如何把一个资源包添加到基于属性文件的此系列)。此示例中的键形式为 "s1" 等。实际的键完全取决于您的选择,只要它们和程序中用于从资源包中获取对象的键相同。键区分大小写。
     

public  class MyResources  extends ListResourceBundle {
      protected Object[][] getContents() {
          return  new Object[][] = {
      //  LOCALIZE THIS
         {"s1", "The disk \"{1}\" contains {0}."},   //  MessageFormat pattern
         {"s2", "1"},                                //  location of {0} in pattern
         {"s3", "My Disk"},                          //  sample disk name
         {"s4", "no files"},                         //  first ChoiceFormat choice
         {"s5", "one file"},                         //  second ChoiceFormat choice
         {"s6", "{0,number} files"},                 //  third ChoiceFormat choice
         {"s7", "3 Mar 96"},                         //  sample date
         {"s8",  new Dimension(1,5)}                  //  real object, not just string
     
//  END OF MATERIAL TO LOCALIZE
     };
   }
 }

  public  class MyResources_fr  extends ListResourceBundle {
      protected Object[][] getContents() {
          return  new Object[][] = {
      //  LOCALIZE THIS
         {"s1", "Le disque \"{1}\" {0}."},           //  MessageFormat pattern
         {"s2", "1"},                                //  location of {0} in pattern
         {"s3", "Mon disque"},                       //  sample disk name
         {"s4", "ne contient pas de fichiers"},      //  first ChoiceFormat choice
         {"s5", "contient un fichier"},              //  second ChoiceFormat choice
         {"s6", "contient {0,number} fichiers"},     //  third ChoiceFormat choice
         {"s7", "3 mars 1996"},                      //  sample date
         {"s8",  new Dimension(1,3)}                  //  real object, not just string
     
//  END OF MATERIAL TO LOCALIZE
     };
   }
}


java lover

你可能感兴趣的:(ListResourceBundle)