#navi(../)
*JWindowを使ったSplash Screenの表示 [#u76ddf25]
>編集者:[[Terai Atsuhiro>terai]]~
作成日:2003-09-25~
更新日:&lastmod;

#contents
**概要 [#v9cffe59]
JWindowを使って、Splash Screenを表示します。起動画面、Splash Windowといった呼び方もあるようです。
以下のサンプルコードは、''%JAVA_HOME%/demo/jfc/SwingSet2/src/SwingSet2.java'' から引用改変したものです。

**サンプルコード [#raad4e3d]
 private JWindow splashScreen;
 private JLabel  splashLabel;
 public void createSplashScreen(String path) {
   ImageIcon img = new ImageIcon(getClass().getResource(path));
   splashLabel  = new JLabel(img);
   splashScreen = new JWindow(getFrame());
   splashScreen.getContentPane().add(splashLabel);
   splashScreen.pack();
   splashScreen.setLocationRelativeTo(null);
 }
 public void showSplashScreen() {
   splashScreen.show();
 }
 public void hideSplash() {
   splashScreen.setVisible(false);
   splashScreen = null;
   splashLabel  = null;
 }
 //コンストラクタ
 public HogeHoge() {
   createSplashScreen("/resources/images/splash.png");
   SwingUtilities.invokeLater(new Runnable() {
     public void run() {
       showSplashScreen();
     }
   });
   //initializePanel();
   //といった初期化などの重い処理の代わりに、このサンプルではsleep
   try{
     Thread.sleep(3000);
   }catch(InterruptedException e) {
   	 System.out.println(e);
   }
   SwingUtilities.invokeLater(new Runnable() {
     public void run() {
       showPanel();
       hideSplash();
     }
   });
 }

-[[サンプルを起動>http://terai.xrea.jp/swing/splashscreen/sample.jnlp]]
-[[jarファイル>http://terai.xrea.jp/swing/splashscreen/sample.jar]]
-[[ソース>http://terai.xrea.jp/swing/splashscreen/src.zip]]

**解説 [#j7466f5a]
スプラッシュ・スクリーンのスレッド処理をSwingUtilities.invokeLaterメソッドを使って行っています。使用する画像は事前に用意しておいてください。上記のサンプルコードでは、クラスパスの通った場所にある ''/resources/images/splash.png'' を読み込んで表示するようになっています。

サンプルの画像は、[[n-Gen>http://www.n-generate.com/download.html]]を使って生成しています。
**コメント [#gc355cfa]
#comment