IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

AWT/Swing Java Discussion :

Probleme avec splash screen


Sujet :

AWT/Swing Java

  1. #1
    Membre habitué
    Étudiant
    Inscrit en
    Janvier 2009
    Messages
    174
    Détails du profil
    Informations personnelles :
    Âge : 38

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Janvier 2009
    Messages : 174
    Points : 140
    Points
    140
    Par défaut Probleme avec splash screen
    j'ai crée un splash screen avec une progress bar. le programme fonctionne très parfaitement lorsque j'exécute directement avec la méthode la méthode main. mais dès que je fait une instance de cette classe dans une autre classe, mon splash ne s'affiche pas juste un carré en gris. la deuxième classe que fait l'instanciation de cette classe est une fenêtre de login (gestion d'authentification avec login,password pour connecter a une base de données postgresql) . Voila mon code entier avec tous les deux classes :


    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
    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
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    public class Login extends JFrame implements ActionListener {
    	Connection con;
    	JPanel pCenter;
    	Image imageFond;
    	Image imageTest;
    	Color JAVAONE_BLUE = new Color(46, 49, 146);
    	static JTextField login=creertextField(10,Color.white,Color.black,BorderFactory.createBevelBorder(1));
    	static JPasswordField mdp=creerpassField(10,Color.white,Color.black,BorderFactory.createBevelBorder(1));
    	static JButton Connexion=new BoutonDegrade("Connexion" ,Color.WHITE, new Color(54, 114, 224), Color.DARK_GRAY,105);
    	static JButton Annuler=new BoutonDegrade("Annuler",Color.WHITE, new Color(54, 114, 224), Color.DARK_GRAY,90);
    	//Font f1=new Font("Arabic Transparent",Font.BOLD,14);
    	Login(){
     
    		try {
    			imageFond = ImageIO.read(getClass().getResourceAsStream("/images/Login.jpg"));
    			} catch (IOException e) {e.printStackTrace();}
     
    		pCenter =new JPanel();
    	        pCenter.setLayout(null);
                JLabel login_label=new JLabel("Nom utilisateur :");
                //login_label.setFont(f1);
                login_label.setBounds(80, 153, 120, 25);
                pCenter.add(login_label);
     
                login.setBounds(200, 153, 205, 25);
    	        pCenter.add(login);
     
    	        JLabel mdp_label=new JLabel("Mot de passe :");
    	        mdp_label.setBounds(80,183,100,25);
    	        pCenter.add(mdp_label);
     
    	        mdp.setBounds(200, 183, 205, 25);
    	        pCenter.add(mdp);
    	        mdp.addActionListener(this);
     
    	        Connexion.setEnabled(true);
    	        //Connexion=new JButton("Connexion");
    	        Connexion.setBounds(200, 260, 105, 27);
    	        pCenter.add(Connexion);
    	        Connexion.addActionListener(this);
     
    	        Annuler.setEnabled(true);
    	        //Annuler=new JButton("Annuler");
    	        Annuler.setBounds(315, 260, 90, 27);
    	        pCenter.add(Annuler);
     
     
    		    Faire_Fond o = new Faire_Fond(imageFond);
    		    pCenter.add(o);
    		    setContentPane(pCenter);
     
    	}
     
    	class Faire_Fond extends JPanel {
     
    		  private Image img;
     
    		  public Faire_Fond(String img) {
    		    this(new ImageIcon(img).getImage());
    		  }
     
    		  public Faire_Fond(Image img) {
    		    this.img = img;
    		    Dimension size = new Dimension(img.getWidth(null), img.getHeight(null));
    		    setPreferredSize(size);
    		    setMinimumSize(size);
    		    setMaximumSize(size);
    		    setSize(size);
    		    setLayout(null);
    		  }
     
    		  public void paintComponent(Graphics g) {
    		    g.drawImage(img, 0, 0, null);
    		  }
    	}
    	public JLabel creerLabel(String titre){
    		JLabel l=new JLabel(titre);
    		//l.setFont(font1);
    	    l.setForeground(JAVAONE_BLUE);
    	return l;
    	}
    	public static JTextField creertextField(int longueur,Color couleur1,Color couleur2,Border bordure){
    		JTextField tf=new JTextField(longueur);
    		tf.setBorder(bordure);
    		//tf.setFont(font1);
    		tf.setBackground(couleur1);
    		tf.setForeground(couleur2);
    	return tf;
    	}
     
     
     
    	public static JPasswordField creerpassField(int longueur,Color couleur1,Color couleur2,Border bordure){
    		JPasswordField tf=new JPasswordField(longueur);
    		tf.setBorder(bordure);
    		//tf.setFont(font1);
    		tf.setBackground(couleur1);
    		tf.setForeground(couleur2);
    	return tf;
    	}
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
            Login inn=new Login();
            inn.setTitle("Connecter au Banque 2009");
            inn.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    		inn.setSize(470,335);
    		try {
    			UIManager.setLookAndFeel(new Plastic3DLookAndFeel());
    		} catch (UnsupportedLookAndFeelException e1) {
    			// TODO Auto-generated catch block
    			e1.printStackTrace();
    		} 
    		inn.center();
    		final Faire_Bouton f=new Faire_Bouton();
    		ImageIcon bank=f.readImageIcon("bank2.jpg");
    	    inn.setIconImage(bank.getImage());
    		inn.setVisible(true);
     
    	}
     
    	public void center() {
    		Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    		Dimension frameSize = getSize();
    		int x = (screenSize.width - frameSize.width) / 2;
    		int y = (screenSize.height - frameSize.height) / 2;
    		setLocation(x, y);
    		}
    	@Override
    	public void actionPerformed(ActionEvent e) {
    		// TODO Auto-generated method stub
    		Object source=e.getSource();
    		if(source==Connexion || source==mdp){
    			try {
     
    con = DriverManager.getConnection("jdbc:postgresql://localhost/centrale",login.getText(),String.copyValueOf(mdp.getPassword()));
    		JOptionPane.showMessageDialog(null, "Authentification réussie");
     		        dispose();
    					new Chargement("banque.jpg", 12000);
    			} catch (SQLException e1) {
    				JOptionPane.showMessageDialog(null,
    					    "Login ou mot de passe Incorrect ",
    					    "Connexion Erreur",
    					    JOptionPane.ERROR_MESSAGE);		
    			}
    		}
    	}
    }


    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
    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
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
     
    public class Chargement extends JWindow implements PropertyChangeListener{
    	private Task task;
    	private JProgressBar progressBar;
    	private BufferedImage image;
     
    	public Chargement(String file, long time){
    		super();
     
    		URL url = getClass().getResource("/images/"+file);
    		progressBar = new JProgressBar(0, 100);
    		//progressBar.setValue(0);
    		progressBar.setIndeterminate(false);
    		//progressBar.setStringPainted(false);
    		getContentPane().add(progressBar, BorderLayout.SOUTH);
     
    		try {
    			image = ImageIO.read(url);
    		} catch (IOException e1) {
    			// TODO Auto-generated catch block
    			e1.printStackTrace();
    		}
    		//setSize(new Dimension(image.getWidth(), image.getHeight()));
    		//setLocationRelativeTo(null);
    		//setAlwaysOnTop(true);
     
    		 // cree un label avec notre image
    		JLabel image2 = new JLabel(new ImageIcon(url));
    		// ajoute le label au panel
    		getContentPane().add(image2, BorderLayout.CENTER);
    		pack(); 
    		// centre le splash screen
    		Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    		Dimension labelSize = image2.getPreferredSize();
    		setLocation(screenSize.width / 2 - (labelSize.width / 2),
    		        screenSize.height / 2 - (labelSize.height / 2)); 
    		// rend le splash screen invisible lorsque l'on clique dessus
    		addMouseListener(new MouseAdapter() {
    		    public void mousePressed(MouseEvent e) {
    		        setVisible(false);
    		        dispose();
    		    }
    		}); 
     
     
            setVisible(true);
    		 setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
    		    //Instances of javax.swing.SwingWorker are not reusuable, so
    		    //we create new instances as needed.
    		    task = new Task();
    		    task.addPropertyChangeListener(this);
    		    task.execute();
    		if(time>0){
    			TimerTask dispose = new TimerTask(){
    				public void run(){dispose();}	
    			};
    			Timer timer = new Timer();
    			timer.schedule(dispose, time);
    			try{
    				Thread.sleep(time);
    			}catch(Exception e){e.printStackTrace();}
    		}
    	}
     
     
    	   class Task extends SwingWorker<Void, Void> {
    	        /*
    	         * Main task. Executed in background thread.
    	         */
    	        @Override
    	        public Void doInBackground() {
    	            Random random = new Random();
    	            int progress = 0;
    	            //Initialize progress property.
    	            setProgress(0);
    	            while (progress < 100) {
    	                //Sleep for up to one second.
    	                try {
    	                    Thread.sleep(random.nextInt(1000));
    	                } catch (InterruptedException ignore) {}
    	                //Make random progress.
    	                progress += random.nextInt(10);
    	                setProgress(Math.min(progress, 100));
    	            }
    	            return null;
    	        }
     
    	        /*
    	         * Executed in event dispatching thread
    	         */
    	        @Override
    	        public void done() {
    	            Toolkit.getDefaultToolkit().beep();
    	            setCursor(null); //turn off the wait cursor
     
    	        }
    	    }
     
     
     
    	    public void propertyChange(PropertyChangeEvent evt) {
    	        if ("progress" == evt.getPropertyName()) {
    	            int progress = (Integer) evt.getNewValue();
    	            progressBar.setValue(progress);
     
    	        } 
    	    }
     
    	public Chargement(String file) throws IOException{
    		this(file,0);	
    	}
    	public void paint(Graphics g){
    		if(image.getColorModel().hasAlpha()){
    			try{
    				Robot robot = new Robot();
    				BufferedImage fond = robot.createScreenCapture(getBounds());
    				MediaTracker tracker = new MediaTracker(this);
    				tracker.addImage(fond,0);
    				tracker.waitForAll();
    				g.drawImage(fond, 0,0,null);
    			}catch(Exception e){e.printStackTrace();}
    		}
    		g.drawImage(image,0,0,null);	
    	}
    }

  2. #2
    Rédacteur/Modérateur

    Avatar de bouye
    Homme Profil pro
    Information Technologies Specialist (Scientific Computing)
    Inscrit en
    Août 2005
    Messages
    6 860
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 48
    Localisation : Nouvelle-Calédonie

    Informations professionnelles :
    Activité : Information Technologies Specialist (Scientific Computing)
    Secteur : Agroalimentaire - Agriculture

    Informations forums :
    Inscription : Août 2005
    Messages : 6 860
    Points : 22 898
    Points
    22 898
    Billets dans le blog
    51
    Par défaut
    Tout d'abord, il ne faut pas lancer la fenetre depuis la Thread du main(). Ensuite, voir ici : http://www.developpez.net/forums/d22...y/#post4249853


    Citation Envoyé par Moi
    Les composants AWT et Swing doivent uniquement être utilisés dans l’EDT. Si un composant est instancié, appelé et manipulé depuis une autre Thread, il peut potentiellement provoquer une erreur dans le programme ou ne pas s’afficher correctement.

    [...]

    Ainsi quand on gère un événement clavier, souris ou de sélection dans un composant on est assuré que :
    1. On est bien dans l’EDT.
    2. le composant n’est pas en train de se redessiner.


    [...]

    Cependant il peut parfois être nécessaire d’effectuer un traitement "plus tard" de manière à essayer d’attendre un moment où le niveau de charge de l’EDT est moins élevé ou pour laisser le temps à l’interface graphique de faire un affichage préliminaire par exemple.

    [...]

    Utiliser la méthode statique invokeLater() de la classe javax.swing.SwingUtilities.

  3. #3
    Membre habitué
    Étudiant
    Inscrit en
    Janvier 2009
    Messages
    174
    Détails du profil
    Informations personnelles :
    Âge : 38

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Janvier 2009
    Messages : 174
    Points : 140
    Points
    140
    Par défaut
    Bonjour,

    merci pour ta réponse, d'accord j'ai utilisé SwingUtilities maintenant pour lancer mon splash mais problème persiste toujours. j'ai procédé comme suit pour lancer mon splash :

    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
     
    public class Login extends JFrame implements ActionListener {
      ...
    		if(source==Connexion || source==mdp){
    			try {
    					SwingUtilities.invokeLater(new Runnable(){
    						@Override
    						public void run() {
    							new Chargement("banque.jpg",12000);	
    						}
    					});
    				//new Ajout_Emp();
    			} catch (SQLException e1) { }
    		}
    ....
    }
    pour vos réponses.

  4. #4
    Rédacteur/Modérateur

    Avatar de bouye
    Homme Profil pro
    Information Technologies Specialist (Scientific Computing)
    Inscrit en
    Août 2005
    Messages
    6 860
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 48
    Localisation : Nouvelle-Calédonie

    Informations professionnelles :
    Activité : Information Technologies Specialist (Scientific Computing)
    Secteur : Agroalimentaire - Agriculture

    Informations forums :
    Inscription : Août 2005
    Messages : 6 860
    Points : 22 898
    Points
    22 898
    Billets dans le blog
    51
    Par défaut
    Le problème n'est pas que pour son lancement mais aussi pour son rafraichissement (voir les phrases en gras dans la citation).

  5. #5
    Membre habitué
    Étudiant
    Inscrit en
    Janvier 2009
    Messages
    174
    Détails du profil
    Informations personnelles :
    Âge : 38

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Janvier 2009
    Messages : 174
    Points : 140
    Points
    140
    Par défaut
    merci pour vos réponse, j'ai réglé mon problème qui était du grâce a la classe Splash. Donc j'ai atteint mon but. je pose ma classe pour que tout le monde s'en profite:




    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
    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
     
     import java.awt.Dimension;
    import java.awt.Graphics;
    import java.awt.Image;
    import java.awt.Rectangle;
    import java.awt.Toolkit;
    import java.io.IOException;
    import java.util.Random;
     
    import javax.imageio.ImageIO;
    import javax.swing.ImageIcon;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JProgressBar;
     
     public class Splash {
     Image imageFond;
     JProgressBar progress;
     Thread thread;
     
     public static JFrame frame;
     Centrale centre=new Centrale();
     public static void main(String[] args){
     new Splash();
     }
     public Splash()
     {
     frame = new JFrame("Chargement");
    	try {
    		imageFond = ImageIO.read(getClass().getResourceAsStream("/images/banque.jpg"));
    		} catch (IOException e) {e.printStackTrace();}
    Fond p = new Fond(imageFond);
    JPanel panel=new JPanel();
    panel.setLayout(null);
     progress = new JProgressBar(0, 100);
     progress.setBounds(new Rectangle(0,278,375,293));
     panel.add(progress);
     panel.add(p);
     frame.setContentPane(panel);
     frame.setSize(375,293);
     Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
     frame.setLocation((screen.width - frame.getSize().width)/2,(screen.height - frame.getSize().height)/2);
     frame.setUndecorated(true);
     frame.setVisible(true);
     frame.setResizable(false);
     thread = new Thread(
     new Progression());
     thread.start();
     }
    	@SuppressWarnings("serial")
    	class Fond extends JPanel {
    		  private Image img;
    		  public Fond(String img) {
    		    this(new ImageIcon(img).getImage());
    		  }
    		  public Fond(Image img) {
    		    this.img = img;
    		    Dimension size = new Dimension(img.getWidth(null), img.getHeight(null));
    		    setPreferredSize(size);
    		    setMinimumSize(size);
    		    setMaximumSize(size);
    		    setSize(size);
    		    setLayout(null);
    		  }
     
    		  public void paintComponent(Graphics g) {
    		    g.drawImage(img, 0, 0, null);
    		  }
    	}
     public class Progression implements Runnable
     {
    public void run()
     {/*
      */  Random random = new Random();
    	            int progressint = 0;
    	            //Initialize progress property.
    	              while (progressint < 100) {
    	                //Sleep for up to one second.
    	                try {
    	                    Thread.sleep(random.nextInt(1000));
    	                } catch (InterruptedException ignore) {}
    	                //Make random progress.
    	                progressint += random.nextInt(10);
                        progress.setValue(progressint);
    	            }
     frame.dispose(); //fermeture de la frame lorsque le chargement est teminé
     }
     }
     }

    la plus belle chose c'est trouver la solution par nous-même

  6. #6
    Rédacteur/Modérateur

    Avatar de bouye
    Homme Profil pro
    Information Technologies Specialist (Scientific Computing)
    Inscrit en
    Août 2005
    Messages
    6 860
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 48
    Localisation : Nouvelle-Calédonie

    Informations professionnelles :
    Activité : Information Technologies Specialist (Scientific Computing)
    Secteur : Agroalimentaire - Agriculture

    Informations forums :
    Inscription : Août 2005
    Messages : 6 860
    Points : 22 898
    Points
    22 898
    Billets dans le blog
    51
    Par défaut
    Punaise, j'adore toujours autant parler a un mur qui n'ecoute pas un mot de ce qu'on lui dit meme si c'est pour son bien...

    1. Lancement du splash dans le main() via SwingUtilities.invokeLater().
    2. Centrage de la fenetre via la methode appropriee.
    3. Changement de la priorite de la Thread a son lancement sinon elle garde celle de l'EDT.
    4. Modification de la valeur de la barre via SwingUtilities.invokeLater().
    5. Fermeture de la fenetre via SwingUtilities.invokeLater().


    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
     
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package test;
     
    import javax.swing.SwingUtilities;
     
    /**
     *
     * @author fabriceb
     */
    public class Main {
     
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) {
            SwingUtilities.invokeLater(new Runnable() {
     
                public void run() {
                    Splash splash = new Splash();
                }
            });
        }
    }
    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
    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
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
     
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package test;
     
    import java.awt.Dimension;
    import java.awt.Graphics;
    import java.awt.Image;
    import java.awt.Rectangle;
    import java.io.IOException;
    import java.util.Random;
     
    import javax.imageio.ImageIO;
    import javax.swing.ImageIcon;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JProgressBar;
    import javax.swing.SwingUtilities;
     
    public class Splash {
     
        Image imageFond;
        JProgressBar progress;
        Thread thread;
        public static JFrame frame;
        //Centrale centre = new Centrale();
     
        public static void main(String[] args) {
            new Splash();
        }
     
        public Splash() {
            frame = new JFrame("Chargement");
            try {
                imageFond = ImageIO.read(getClass().getResourceAsStream("/images/banque.jpg"));
            } catch (IOException e) {
                e.printStackTrace();
            }
            Fond p = new Fond(imageFond);
            JPanel panel = new JPanel();
            panel.setLayout(null);
            progress = new JProgressBar(0, 100);
            progress.setBounds(new Rectangle(0, 278, 375, 293));
            panel.add(progress);
            panel.add(p);
            frame.setContentPane(panel);
            frame.setSize(375, 293);
            frame.setLocationRelativeTo(null);
            frame.setUndecorated(true);
            frame.setVisible(true);
            frame.setResizable(false);
            thread = new Thread(new Progression());
            thread.setPriority(Thread.NORM_PRIORITY);
            thread.start();
        }
     
        @SuppressWarnings("serial")
        class Fond extends JPanel {
     
            private Image img;
     
            public Fond(String img) {
                this(new ImageIcon(img).getImage());
            }
     
            public Fond(Image img) {
                this.img = img;
                Dimension size = new Dimension(img.getWidth(null), img.getHeight(null));
                setPreferredSize(size);
                setMinimumSize(size);
                setMaximumSize(size);
                setSize(size);
                setLayout(null);
            }
     
            public void paintComponent(Graphics g) {
                g.drawImage(img, 0, 0, null);
            }
        }
     
        public class Progression implements Runnable {
     
            public void run() {/*
                 */ Random random = new Random();
                int progressint = 0;
                //Initialize progress property.
                while (progressint < 100) {
                    //Sleep for up to one second.
                    try {
                        Thread.sleep(random.nextInt(1000));
                    } catch (InterruptedException ignore) {
                    }
                    //Make random progress.
                    progressint += random.nextInt(10);
                    final int value = progressint;
                    SwingUtilities.invokeLater(new Runnable() {
     
                        public void run() {
                            progress.setValue(value);
                        }
                    });
     
                }
                SwingUtilities.invokeLater(new Runnable() {
     
                    public void run() {
                        frame.dispose(); //fermeture de la frame lorsque le chargement est teminé
                    }
                });
            }
        }
    }
    Tant qu'a faire une JFrame non-decoree et non-redimentionnable autant utiliser une JWindow

  7. #7
    Membre habitué
    Étudiant
    Inscrit en
    Janvier 2009
    Messages
    174
    Détails du profil
    Informations personnelles :
    Âge : 38

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Janvier 2009
    Messages : 174
    Points : 140
    Points
    140
    Par défaut
    merci, je procéderai comme vous m'avez dit la prochaine fois.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Splash-screen avec JSmooth
    Par remi.thevenoux dans le forum Build
    Réponses: 0
    Dernier message: 17/03/2010, 19h21
  2. Splash Screen avec Netbeans 6.1
    Par NizarK dans le forum NetBeans
    Réponses: 6
    Dernier message: 28/10/2008, 16h53
  3. splash screen avec jbuilder
    Par gridsof dans le forum JBuilder
    Réponses: 1
    Dernier message: 17/07/2007, 00h03
  4. Problème avec le Splash screen
    Par Hoopsy dans le forum C++Builder
    Réponses: 4
    Dernier message: 07/06/2007, 22h24
  5. [TP] Problème avec clear screen
    Par lapeitedor dans le forum Turbo Pascal
    Réponses: 2
    Dernier message: 25/11/2006, 12h37

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo