隨筆-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高級
          主站蜘蛛池模板: 留坝县| 濉溪县| 贺兰县| 黄平县| 满洲里市| 来宾市| 平江县| 自贡市| 凤冈县| 陵水| 兴仁县| 华容县| 穆棱市| 神池县| 平昌县| 渝北区| 宿松县| 白朗县| 明溪县| 甘泉县| 山西省| 宜春市| 彰化市| 长岛县| 田林县| 乐都县| 庆城县| 集贤县| 朝阳县| 黎川县| 从化市| 鸡泽县| 鄂托克前旗| 交口县| 上饶市| 长泰县| 明溪县| 台安县| 喀什市| 泌阳县| 清水河县|