Java程式的漢化

來源:互聯網
上載者:User

任務:有一個簡單的SWT視窗,如:

 

對它進行漢化。

使用的開發工具是Eclipse 3.7。

1、選中以上視窗所對應的.java檔案(本例中是MainFrame.java),右擊,依次選擇 Source — Externalize Strings ,在開啟的對話方塊,保持預設狀態,選擇 Next ,直到單擊 Finish ,會產生兩個檔案:Messages.java 與 messages.properties 。

messages.properties中的內容如下:

view source

 

print?

1 MainFrame_0=/javax/swing/plaf/basic/icons/JavaCup16.png
2 MainFrame_1=Student Information
3 MainFrame_2=Name
4 MainFrame_3=Sex
5 MainFrame_4=Number
6 MainFrame_5=Class
7 MainFrame_6=Male
8 MainFrame_7=Female

2、將 messages.properties 檔案複製到電腦上Jdk中的bin檔案夾中。例如,我放在D:\Program Files\Java\jdk1.6.0_25\bin目錄下。

3、用記事本開啟bin目錄下的 messages.properties 檔案,將其中=號後面的英語單詞替換成想要的中文。替換後,內容如下:

view source

 

print?

1 MainFrame_0=/javax/swing/plaf/basic/icons/JavaCup16.png
2 MainFrame_1=學生資訊
3 MainFrame_2=姓名
4 MainFrame_3=性別
5 MainFrame_4=學號
6 MainFrame_5=班級
7 MainFrame_6=男
8 MainFrame_7=女

(註:/javax/swing/plaf/basic/icons/JavaCup16.png 表示的是一個路徑,不用管它)

4、接下來是比較關鍵的一步。選擇 開始 — 運行 ,輸入 cmd ,開啟命令視窗,接下來以此要輸入的命令如所示:

斷行符號後,會產生一個 newmessages.properties 檔案,內容如下:

view source

 

print?

1 MainFrame_0=/javax/swing/plaf/basic/icons/JavaCup16.png
2 MainFrame_1=\u5b66\u751f\u4fe1\u606f
3 MainFrame_2=\u59d3\u540d
4 MainFrame_3=\u6027\u522b
5 MainFrame_4=\u5b66\u53f7
6 MainFrame_5=\u73ed\u7ea7
7 MainFrame_6=\u7537
8 MainFrame_7=\u5973

5、用上述內容替換 Eclipse 工程下的 messages.properties 檔案的內容,儲存。運行程式,效果如:

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.