TITLE:JWindowを使ったSplash Screenの表示
#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'' から引用改変したものです。

#screenshot

**サンプルコード [#raad4e3d]
#code{{
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");
  EventQueue.invokeLater(new Runnable() {
    public void run() {
      showSplashScreen();
    }
  });
  //initializePanel();
  //といった初期化などの重い処理の代わりに、このサンプルではsleep
  try{
    Thread.sleep(3000);
  }catch(InterruptedException e) {
  	 System.out.println(e);
  }
  EventQueue.invokeLater(new Runnable() {
    public void run() {
      showPanel();
      hideSplash();
    }
  });
}
}}
-&jnlp;
-&jar;
-&zip;

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

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

Java SE 6 では、起動時にスプラッシュ・スクリーンとして表示する画像をコマンドラインで、またはmanifest.mfで指定したり、SplashScreenオブジェクトを生成してこれを表示したりすることができるようです。
-[[参考>http://java.sun.com/developer/JDCTechTips/2005/tt1115.html#1]]
-[[New Splash-Screen Functionality in Mustang>http://java.sun.com/developer/technicalArticles/J2SE/Desktop/mustang/splashscreen/]]

**コメント [#gc355cfa]
#comment