1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
|
// Classe principale de lancement de l'application'
public class Main implements Runnable
{
public static void main(String[] args)
{
Toolkit.getDefaultToolkit().setDynamicLayout(true);
try
{
UIManager.setLookAndFeel(new PgsLookAndFeel());
}
catch (Exception e) {}
EventQueue.invokeLater(new Main());
}
// Methode de lancement de l'application
public void run()
{
// on récupère le splash screen
final SplashScreen splash = SplashScreen.getSplashScreen();
if(splash != null)
{
showSplash(splash);
}
showFrame();
}
// Methode d'affichage du splash screen
private void showSplash(SplashScreen splash)
{
// on crée un objet Graphics afin de dessiner au dessus du splash screen
final Graphics2D g = (Graphics2D)splash.createGraphics();
g.setColor(Color.BLACK);
g.drawRect(0,0,(int)splash.getSize().getWidth()-1,(int)splash.getSize().getHeight()-1);
final Rectangle rect = new Rectangle(20, splash.getSize().height - 50, 120, 15);
final int loadingY = rect.y + rect.height * 2;
// fond transparent
g.setBackground(new Color(0, 0, 0, 0));
int sum = 0 ;
for (int i=0; i < 5 ; i++)
{
g.setColor(Color.BLACK);
g.drawRect(0,0,(int)splash.getSize().getWidth()-1,(int)splash.getSize().getHeight()-1);
g.clearRect(rect.x, rect.y, rect.width * 3, rect.height * 3);
g.drawString("Chargement...Veuillez patienter un instant ", rect.x, rect.y + rect.height);
g.setColor(Color.RED);
// on simule le chargement du module
for(int j=0; j < 5; j++)
{
sum += 20*j*Math.random() ;
// dessine la barre de chargement
g.fillRect(rect.x, loadingY, sum, 5);
// mets à jour l'affichage du splash
splash.update();
}
}
g.fillRect(rect.x, loadingY, (int)splash.getSize().getWidth()-5, 5);
}
// Methode de lancement de d'application
private void showFrame()
{
// on affiche la fenêtre principale de l'application
new Thread()
{
public void run()
{
FenetrePrincipale frame = new FenetrePrincipale();
//FenetreTest t = new FenetreTest();
}
}.start();
}
} |
Partager