Amigos utilizo os seguintes métodos para a apresentação de Splash. ele rodar mais quando eu pego meu .jar juntamente
com a pasta lib e jogo este projeto em outra pasta a imagem não mais aparece.
package controle;
import controle.utils.Utils;
import java.awt.*;
import javax.swing.*;
public class SplashScreen extends JWindow {
private int duration;
public SplashScreen(int d) {
duration = d;
}
public void showSplash() {
JPanel content = (JPanel) getContentPane();
content.setBackground(Color.white);
int width = 474;//474
int height = 370;//200
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
int x = (screen.width - width) / 2;//2
int y = (screen.height - height) / 2;//2
setBounds(x, y, width, height);
Utils u = new Utils();
u.getApplicationPath();
String caminho = u.getApplicationPath() + "/splash_guj.jpg";
System.out.println(caminho.replace("\", "/"));
JLabel label = new JLabel(new ImageIcon(caminho));
JLabel copyrt = new JLabel("JAVA TECNOLOGIA,TODOS OS DIREITOS RESERVADOS", JLabel.CENTER);
copyrt.setFont(new Font("Sans-Serif", Font.BOLD, 12));
content.add(label, BorderLayout.CENTER);
content.add(copyrt, BorderLayout.SOUTH);
setVisible(true);
try {
Thread.sleep(duration);
} catch (Exception e) {
}
setVisible(false);
}
public void showSplashAndExit() {
showSplash();
System.exit(0);
}
@SuppressWarnings("deprecation")
public static void main(String[] args) {
SplashScreen splash = new SplashScreen(2000);
splash.showSplash();
new menu().setVisible(true);
}
}
public String getApplicationPath() {
//u.getApplicationPath());
String url = getClass().getResource(getClass().getSimpleName() + ".class").getPath();
File dir = new File(url).getParentFile();
String path = null;
if (dir.getPath().contains(".jar")) {
path = findJarParentPath(dir);
} else {
path = dir.getPath();
}
try {
return URLDecoder.decode(path, "UTF-8");
} catch (UnsupportedEncodingException e) {
return path.replace("%20", " ");
}
}
private String findJarParentPath(File jarFile) {
while (jarFile.getPath().contains(".jar")) {
jarFile = jarFile.getParentFile();
}
return jarFile.getPath().substring(6);
}
}
Obrigado.,