Código
import javax.swing.*;
import java.awt.*;
import java.io.File;
/**
*
* @author Afsoon de elhacker para la gente de elhacker y el resto, permito
* su distribución con la acredeticación del autor del código base
*
*/
public class Splash extends JFrame {
private JLabel label;
private Threadbar thread;
private JProgressBar bar;
public Splash(){
super("");
defineVentana();
//Here create the new thread
thread = new Threadbar(bar);
//Start Thread
thread.start();
//Here get point x,y where will appear Window
// This Operations is provided by Darhius elhacker
int x = (int)((java.awt.Toolkit.getDefaultToolkit().getScreenSize().width)- this.getSize().width)/2;
int y = (int)((java.awt.Toolkit.getDefaultToolkit().getScreenSize().height)- this.getSize().height)/2;
//Size and basic
this.setLocation(x, y);
this.setSize(400,300);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
//Empty the memory
thread = null;
}
public void defineVentana(){
this.setLayout(new BorderLayout());
//Image Splash
ImageIcon jpg = new ImageIcon(getClass().getResource(/*Insertar ruta de la imagen*/));
label = new JLabel(jpg);
//Progress
bar = new JProgressBar();
bar.setBorderPainted(true);
bar.setForeground(new Color(0, 0, 55));
bar.setStringPainted(true);
//Add component in the Layout
this.add(label, BorderLayout.CENTER);
this.add(bar, BorderLayout.SOUTH);
}
public void showError(Exception e){
System.err.print(e);
}
public void pausa(int mSeg){
try
{
Thread.sleep(mSeg);
}catch(Exception e)
{
showError(e);
}
}
class Threadbar extends Thread{
private JProgressBar bar;
public Threadbar(JProgressBar bar)
{
this.bar = bar;
}
public void run(){
for(int i=0;i <= 100; i++)
{
bar.setValue(i);
pausa(100);
}
}
}
}










Autor


En línea








