import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.net.*;
import javax.imageio.*;
import javax.swing.*;
import javax.swing.border.*;
public class SplashBar extends Frame {
public SplashBar() {
super("aa");
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent evt) {
exitForm(evt);
}
});
setSize(400,300);
setLocationRelativeTo(null);
URL url = SplashBar.class.getResource("KleinLogo.jpg");
Image image = null;
if (url != null)
try {image = ImageIO.read(url);} catch (IOException ex) {}
splash = new Splash_( image, null, null);
splash.setVisible(true);
try {Thread.sleep(1000);} catch (InterruptedException ex) {}
splash.showStatus(null, 10);
try {Thread.sleep(1000);} catch (InterruptedException ex) {}
splash.showStatus(null, 50);
try {Thread.sleep(1000);} catch (InterruptedException ex) {}
splash.close();
}
/** Exit the Application */
private void exitForm(WindowEvent evt) {
System.exit(0);
}
public static void main(String args[]) {new SplashBar().setVisible(true);}
public static Splash_ splash = null;
}
class Splash_ extends JWindow {
private JProgressBar progress;
private Image imageSplash, imageBackground;
private class UpdateStatus implements Runnable {
public UpdateStatus(String status, int pc) {
message = status;
value = pc;
}
public void run() {
progress.setValue(value);
progress.setString(message);
}
private String message;
private int value;
}
private class CloseSplashScreen implements Runnable {
public void run() {
setVisible(false);
dispose();
}
}
/**
* SplashScreen erzeugen
*/
public Splash_(Image coolPicture, String initialMessage, String title) {
if(coolPicture != null){
setSize(coolPicture.getWidth(this),coolPicture.getHeight(null)+25);
}else{
setSize(200,200);
}
setLocationRelativeTo(null);
MyPanel myPanel=new MyPanel(getSize());
Color fgX = new Color(85,43,0);
JLabel labelT =new JLabel(title,JLabel.CENTER) ;
labelT.setForeground(fgX);
Dimension preferredSize1 = labelT.getPreferredSize() ;
double height1 = preferredSize1.getHeight() ;
double width1 = preferredSize1.getWidth() ;
height1=height1+20;
preferredSize1.setSize(width1, height1) ;
labelT.setPreferredSize(preferredSize1);
if (title != null) myPanel.add(labelT,BorderLayout.NORTH);
progress = new JProgressBar(0,100);
progress.setForeground(fgX) ;
Dimension preferredSize = progress.getPreferredSize() ;
double height = preferredSize.getHeight() ;
double width = preferredSize.getWidth() ;
height=height/2.0;
preferredSize.setSize(width, height) ;
progress.setString(initialMessage);
myPanel.add(progress,BorderLayout.SOUTH);
// progress.setStringPainted(true); //progressbar mit Beschriftung
progress.setPreferredSize(preferredSize); //schmalere progressbar
// progress.setBorderPainted(false) ; //progressbar ohne Rand
// myPanel.setBorder(new BevelBorder(BevelBorder.RAISED));
// myPanel.setBorder(new LineBorder(fgX, 2));
progress.setBackground(new Color(254,243,224)) ;
getContentPane().add(myPanel);
imageSplash = coolPicture;
try {
imageBackground = new Robot().createScreenCapture( getBounds() );
} catch (AWTException ex) {
ex.printStackTrace();
}
}
/**
* Den splash screen schliessen und alle resources freigeben die damit zusammenhängen.
* Diese Methode ist thread safe und kann von jedem Thread aufgerufen werden.
*/
public void close() {
if (isVisible()) {
SwingUtilities.invokeLater(new CloseSplashScreen());
}
}
/**
* Den splash screen sichtbar/unsichtbar machen.
*/
public void setVisible(boolean show) {
if (show) {
pack();
setLocationRelativeTo(null);
}
super.setVisible(show);
}
/**
* Status der progressbar ändern.
* Diese Methode ist thread safe und kann von jedem Thread aufgerufen werden.
*/
public void showStatus(String message, int percent) {
if (isVisible()) {
SwingUtilities.invokeLater(new UpdateStatus(message, percent));
}
}
class MyPanel extends JPanel{
public MyPanel(Dimension size){
setLayout(new BorderLayout());
setPreferredSize(size);
}
public void paintComponent(Graphics g){
super.paintComponent(g);
if( imageBackground != null ) {
g.drawImage( imageBackground, 0, 0, this );
}
g.drawImage( imageSplash, 0, 0, this );
}
}
}