import java.awt.*;
import javax.swing.*;
public class SplashScreen extends JWindow {
private Frame parent;
private JProgressBar progressBar;
private JLabel splashImage;
public SplashScreen(final Frame f, String fileName){
super(f);
parent = f;
splashImage = new JLabel();
splashImage.setIcon(new ImageIcon(fileName));
progressBar = new JProgressBar();
progressBar.setBorderPainted(true);
progressBar.setStringPainted(true);
progressBar.setMaximum(10);
getContentPane().add(splashImage, BorderLayout.CENTER);
getContentPane().add(progressBar, BorderLayout.SOUTH);
pack();
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension labelSize = splashImage.getPreferredSize();
setLocation(screenSize.width/2 - (labelSize.width/2),
screenSize.height/2 – (labelSize.height/2));
}
public void showSplash(int waitTime){
final int pause = waitTime;
final Runnable closerRunner = new Runnable(){
public void run(){
setVisible(false);
dispose();
parent.setVisible(true);
}
};
Runnable waitRunner = new Runnable(){
public void run(){
try{
for (int i=1; i<=10; i++){
setProgress(i);
Thread.sleep(pause);
}
SwingUtilities.invokeAndWait(closerRunner);
}
catch(Exception e){
e.printStackTrace();
}
}
};
setVisible(true);
Thread splashThread = new Thread(waitRunner, “SplashThread”);
splashThread.start();
}
private void setProgress(int current){
final int progress = current;
final String status = “Loading… ” + current * 10 + ” %”;
SwingUtilities.invokeLater(new Runnable(){
public void run() {
progressBar.setValue(progress);
progressBar.setString(status);
}
});
}
}
*Cara penggunaan (pemanggilan dari class lain) :
SplashScreen splashScreen =
new SplashScreen(this, “YOUR IMAGE FILE HERE”);
splashScreen.showSplash(150);