A voir également:
- [java]utiliser un splash Screen
- Waptrick java football - Télécharger - Jeux vidéo
- Jeux java itel football - Télécharger - Jeux vidéo
- Utiliser chromecast - Guide
- Java apk - Télécharger - Langages
- Jeux java itel 5360 ✓ - Forum Mobile
2 réponses
Utilisateur anonyme
13 févr. 2007 à 21:01
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:
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
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