Kenji Tachibana's Weblog

« 前の日(Mar月 30日, 2009年) | 日付別メイン | 次の日(Apr月 1日, 2009年) »

http://blogs.sun.com/kenji/date/20090401 2009年 4月 01日 水曜日

JavaFX: Display localized Screen on runtime

This is English version of this blog



JavaFX.COM has many interesting samples for JavaFX. I was asked JavaFX sample team, to create a sample for changing the display language on runtime. So, I've created it and up it on my blog, first.

Sample for Runtime localization (Web Start, use signed jar)

If you see the source code, you can find that this example is using the Locale.setDefault Java class method, like change the default locale and reload the localized strings from .fxproperties.

The clock in botton of the screen is created with refering to Building a JavaFX Application Using NetBeans IDE .
However, to display the time, use extended formatter to display localized time format.


LocalizedDate = "{%tEc now}";

"now" is the Date Object from Java class, and put the localized time strings to LocalizedDate (String).
This time is displayed in each timezone's time. So, please compare the English (Los Angeles) and Japanese (Tokyo).

Also, this sample has the round image animation (?), which is I've wanted to create from before. When you click the language button, world map will move to center the city where represent specified language and Timezone.
- English : Los Angeles
- Japanese: Tokyo
- Simplified Chinese: Shanghai (Because timezone need to specify Shanghai (not Beijing) in Java)
- Korean: Seoul
- Brazilian Portuguese: Sao Paulo

This is simply implemented with 3 lined world map, and display only center one and move 3 maps together to left or right.

Source Code






Displayed in English. Then, click Japanese (日本語) button,

Chnage to Japanese.

JavaFX ランタイムローカリゼーションのサンプル

JavaFX.COM のページにサンプルがたくさんありますが、JavaFX で動的に表示言語がかわるサンプルを作らないか?というお誘いに乗って、作ってみました。もちろん NetBeans で!

動的に表示言語がかわるサンプル (Web Start, 署名付き jar 使用)

サンプルに載せてもらえるかどうかはわからないので、とりあえず blog に載せました。

ソースコードを見るとわかるのですが、切り替えは Java の Locale.setDefault メソッドを使っています。ロケールを切り替えて、もう一度メッセージを .fxproperties から読み直してる、という感じです。

画面したの時計は、 Building a JavaFX Application Using NetBeans IDE を見ながら、ローカライズだけしてみたのですが、さくらばさんが、 ついにベールを脱いだJavaFX - 国際化 で、すでに作成されていましたね... 私のソースより、こちらを見たほうがずっと参考になると思います。

また、このサンプルは、ローカリゼーション関連だけではなく、
前からやってみたかった、「ぐるっと一周している画像のアニメーション」も作ってみています。各言語ボタンをクリックすると、世界地図が動いて、その言語にあった都市を中心にした世界地図になります。単に世界地図を3枚横に並べて、中心の画像だけ左右に動かしているのですが、作ってみるとなかなか面白かったです。

ソースコード






英語の画面。ここで、「日本語」をクリックすると、

日本語に切り替わります。


Valid HTML! Valid CSS!

This is a personal weblog, I do not speak for my employer.