Bueno ahora el código para hacer un splash, para que no hagan en adelante temas para que la gente pregunte sobre eso, es funcional, esta preparado el hilo de la barra, solo tenéis que insertar la ruta de la imagen (la tenéis que insertar en bin en el package[es lo que hago yo] la imagen y si quereís creais una carpeta), configuráis el tamaño de la ventana y lo que quieres que haga el hilo, eso es todo creo y aquí el codigo
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 Threadbar thread;
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(){
//Image Splash
//Progress
bar.setBorderPainted(true);
bar.
setForeground(new Color(0,
0,
55)); bar.setStringPainted(true);
//Add component in the Layout
}
}
public void pausa(int mSeg){
try
{
{
showError(e);
}
}
class Threadbar
extends Thread{
{
this.bar = bar;
}
public void run(){
for(int i=0;i <= 100; i++)
{
bar.setValue(i);
pausa(100);
}
}
}
}
si alguien tiene un algoritmo de centrado de ventanas mas "exacto" porque lo he probado de nuevo ese en otro ordenador y no puede estar mas descentrado, lo edito el archivo y asi esta mejor
si alguien tiene un algoritmo de centrado de ventanas mas "exacto" porque lo he probado de nuevo ese en otro ordenador y no puede estar mas descentrado, lo edito el archivo y asi esta mejor
Hola, es sencillo.
Solo obtienes la dimensión de la pantalla, la dimensión de tú frame, haces algunas operaciones y listo.
public Splash(){
super("");
defineVentana();
thread = new Threadbar(bar);
thread.start();
this.setSize(400,300);
java.
awt.
Dimension screenSize
= java.
awt.
Toolkit.
getDefaultToolkit().
getScreenSize(); java.
awt.
Dimension frameSize
= this.
getSize(); int width = (int)screenSize.width - (int)frameSize.width;
int height = (int)screenSize.height - (int) frameSize.height;
int x = width /2;
int y = height/2;
this.setLocation(x, y);
this.
setDefaultCloseOperation(JFrame.
EXIT_ON_CLOSE); this.setVisible(true);
thread = null;
}
Aunque claro, todo eso se puede resumir a esto.
public Splash(){
super("");
defineVentana();
thread = new Threadbar(bar);
thread.start();
this.setSize(400,300);
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; this.setLocation(x, y);
this.
setDefaultCloseOperation(JFrame.
EXIT_ON_CLOSE); this.setResizable(false);
this.setVisible(true);
thread = null;
}
Y mejor aun sin tanto cálculo.
public Splash(){
super("");
defineVentana();
thread = new Threadbar(bar);
thread.start();
this.setSize(400,300);
this.setLocationRelativeTo(null);
this.
setDefaultCloseOperation(JFrame.
EXIT_ON_CLOSE); this.setResizable(false);
this.setVisible(true);
thread = null;
}
Un saludo.
int widht = (int) d.getWidth()/4;
PD. es width, no widht. :xD