A splash screen for an application : Splash Screen « Swing « Java Tutorial






import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Toolkit;

import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JWindow;

class SplashScreen extends JWindow {
  private int duration;

  public SplashScreen(int d) {
    duration = d;

    JPanel content = (JPanel) getContentPane();
    content.setBackground(Color.white);
    int width = 450;
    int height = 115;
    Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
    int x = (screen.width - width) / 2;
    int y = (screen.height - height) / 2;
    setBounds(x, y, width, height);

    content.add(new JLabel("asdf"), BorderLayout.CENTER);
    Color oraRed = new Color(156, 20, 20, 255);
    content.setBorder(BorderFactory.createLineBorder(oraRed, 10));

    setVisible(true);
    try {
      Thread.sleep(duration);
    } catch (Exception e) {
    }
    setVisible(false);
  }
  public static void main(String[] args) {
    SplashScreen splash = new SplashScreen(10000);
  }
}








14.79.Splash Screen
14.79.1.JDK6 Splash Screen
14.79.2.SplashScreen with custom painting
14.79.3.SplashScreen in action
14.79.4.A splash screen for an application
14.79.5.A progress bar indicating the progress of application initialization