隨筆-59  評論-31  文章-0  trackbacks-0
              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
               };
             }
          }
          posted on 2012-01-04 14:29 RoyPayne 閱讀(315) 評論(0)  編輯  收藏 所屬分類: java高級
          主站蜘蛛池模板: 卓尼县| 灵川县| 洪雅县| 乌审旗| 扎兰屯市| 商水县| 安福县| 潮州市| 苍溪县| 昌邑市| 长海县| 通渭县| 望城县| 广昌县| 晋州市| 大邑县| 买车| 兴仁县| 静乐县| 华蓥市| 手游| 德昌县| 温泉县| 吉水县| 饶平县| 庄浪县| 嘉善县| 新密市| 淮阳县| 类乌齐县| 彰化县| 石河子市| 泰来县| 长丰县| 寻乌县| 金山区| 汝州市| 新巴尔虎左旗| 嵩明县| 湖南省| 涡阳县|