隨筆-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 閱讀(323) 評論(0)  編輯  收藏 所屬分類: java高級
          主站蜘蛛池模板: 临泽县| 成都市| 瑞安市| 横山县| 资中县| 方城县| 东兰县| 普兰店市| 扬州市| 贵阳市| 台东县| 张北县| 许昌县| 元朗区| 朝阳区| 杭锦后旗| 广西| 库车县| 尼木县| 桑植县| 筠连县| 炎陵县| 景德镇市| 丰镇市| 巴里| 穆棱市| 绥芬河市| 博客| 百色市| 隆化县| 赤水市| 本溪市| 马尔康县| 兴国县| 甘谷县| 旌德县| 阆中市| 油尖旺区| 石台县| 登封市| 英山县|