SplashScreen with custom painting : Splash Screen « Swing « Java Tutorial






import java.awt.Color;
import java.awt.Dimension;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.SplashScreen;

public class SplashScreenDemo {
  public static void main(String[] args) {
    SplashScreen splashScreen = SplashScreen.getSplashScreen();
    Dimension size = splashScreen.getSize();
    int borderDim = (int) (size.height * 0.05);
    Graphics g = splashScreen.createGraphics();
    g.setColor(Color.blue);
    for (int i = 0; i < borderDim; i++)
      g.drawRect(i, i, size.width - 1 - i * 2, size.height - 1 - i * 2);

    FontMetrics fm = g.getFontMetrics();
    int sWidth = fm.stringWidth("Initializing...");
    int sHeight = fm.getHeight();
    if (sWidth < size.width && 2 * sHeight < size.height) {
      g.setColor(Color.blue);
      g.drawString("Initializing...", (size.width - sWidth) / 2, size.height
          - 2 * sHeight);
    }

    splashScreen.update();

    try {
      Thread.sleep(5000);
    } catch (InterruptedException e) {
    }
  }
}








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