Bonjour,
Je souhaiterai afficher une splashscreen à l'ouverture de mon application (SWING en JDK 1.4).
Pour cela j'ai récupéré une classe SplashScreen sur le net :

http://examples.oreilly.com/jswing2/...ashScreen.java
que j'ai un peu bidouillé, cf ci-dessous.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
 
 
public class SplashScreen extends JWindow{
  private int duration;
  public SplashScreen(int d) {
    duration = d;
  }
 
  // A simple little method to show a title screen in the center
  // of the screen for the amount of time given in the constructor
  public void showSplash() {
    JPanel content = (JPanel)getContentPane();
    content.setBackground(Color.white);
 
    // Set the window's bounds, centering the window
    int width = 450;
    int height =300;
    Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
    int x = (screen.width-width)/2;
    int y = (screen.height-height)/2;
    setBounds(x,y,width,height);
 
    // Build the splash screen
    //JLabel label = new JLabel(new ImageIcon("oreilly.gif"));
    JLabel lab = new JLabel("veuillez patientez");
    JLabel copyrt = new JLabel
      ("Copyright 2002, O'Reilly & Associates", JLabel.CENTER);
    copyrt.setFont(new Font("Sans-Serif", Font.BOLD, 12));
    //content.add(label, BorderLayout.CENTER);
    content.add(copyrt);
    content.add(lab);
 
    Color oraRed = new Color(156, 20, 20,  255);
    content.setBorder(BorderFactory.createLineBorder(oraRed, 10));
 
    // Display it
    setVisible(true);
 
    // Wait a little while, maybe while loading resources
//    try { Thread.sleep(duration); } catch (Exception e) {}
//
//    setVisible(false);
  }
 
  public void showSplashAndExit() {
    showSplash();
    //System.exit(0);
  }
 
  public static void main(String[] args) {
    // Throw a nice little title page up on the screen first
    SplashScreen splash = new SplashScreen(10000);
    // Normally, we'd call splash.showSplash() and get on with the program.
    // But, since this is only a test...
    splash.showSplashAndExit();
  }
}
Mais j'ai du mal à l'intégrer dans mon code (simplifié) ci-dessous.
Ma splashScreen ne s'affiche pas....Est-ce parce qu'elle hérite de JWindow alors que mon application de JFrame ? L'idée étant que la Splash screen se ferme lorsque mon long traitement est terminé !


Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
 
 
public class MailingPlus extends JFrame {
 
// constructeur
public MonApplication() {
 
 .....//Traitements longs
}
 
public static void main2(String[] args) {
		// 
	SwingUtilities.invokeLater(new Runnable() {
			public void run() {
 
				Date date = new Date();
 
				SplashScreen splash = new SplashScreen(1);
				splash.showSplash();
 
				MailingPlus thisClass = new MailingPlus();
 
				thisClass.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 
				thisClass.setResizable(false);
 
				splash.setVisible(false);
 
				thisClass.setVisible(true);
 
			}
		});
 
}
}
Quelqu'un a -t-il une idée pourquoi je n'arrive pas à afficher ma JWindow ? si je remplace par 'SplashScreen extends JFrame", ca fonctionne mais c'est pas beau....

Merci