[java]utiliser un splash Screen

Fermé
javaclipse - 12 févr. 2007 à 15:07
 Hashcode - 29 mai 2008 à 16:28
Bonjour à tous,

j'ai créé une application sous éclipse. J'aimerais que pendant le lancement de l'application j'ai un splash screen qui s'affiche au lieu d'attendre 10 secondes que l'application s'affiche. J'ai fais donc un rpojet de développement de plug-in. J'ai fais un .product de mon application. Je ne sais pas comment rajouter sa. Je crois que c'est un plug-in mais j'en sais pas plus. Pouvez-vous m'aider svp?

Merci d'avance.
A voir également:

2 réponses

Utilisateur anonyme
13 févr. 2007 à 21:01
Salut!

J'ai créé il y a quelque temps une petite classe utilitaire qui permet d'afficher un splashscreen.

En voici le code:

import java.awt.Dimension;
import java.awt.Toolkit;

import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JWindow;

public class SplashWindow extends JWindow {
	private static SplashWindow instance;
	private long minDuration;

	private SplashWindow(String imagePath, long minDuration) {
		super();
		this.minDuration = minDuration;
		Dimension screenDimension = Toolkit.getDefaultToolkit().getScreenSize();
		if (imagePath != null && !imagePath.equals("")) {
			ImageIcon img = new ImageIcon(imagePath);
			int imgHeight = img.getIconHeight();
			int imgWidth = img.getIconWidth();
			int imgX = (screenDimension.width - imgWidth) / 2;
			int imgY = (screenDimension.height - imgHeight) / 2;
			JLabel jl_img = new JLabel(img);
			jl_img.setPreferredSize(new Dimension(imgWidth, imgHeight));
			getContentPane().add(new JLabel(img));
			setLocation(imgX,imgY);
		} else {
			setLocation(screenDimension.width / 2, screenDimension.height / 2);
		}
		pack();
		setVisible(true);
		long tEnd = System.currentTimeMillis() + minDuration;
		while (System.currentTimeMillis() < tEnd) {
		}
	}

	public static SplashWindow getInstance(String imagePath, long minDuration) {
		if (instance == null) {
			instance = new SplashWindow(imagePath, minDuration);
		}
		return instance;
	}

	public static SplashWindow getInstance(String imagePath) {
		if (instance == null) {
			instance = new SplashWindow(imagePath, 0);
		}
		return instance;
	}

	public static SplashWindow getInstance() {
		return getInstance(null, 0);
	}

	public void end() {
		setVisible(false);
		dispose();
	}

}


Tu en crées une instance en appelant la méthode statique getInstance() avec comme paramètre le chemin de l'image à afficher et - pour l'autre méthode statique getInstance() - le temps minimum d'affichage de l'image (bloquant pou le reste du code).

Pour le faire diparaître, appelle la méthode end() sur l'instance.

Amélioration à apporter (je t'en laisse le soin): transformer la classe en Thread ou Runnable

;-)
HackTrack
6
Voila un bel exemple de code crado
1