Spécifier l'affichage d'une chaîne

azoinf -  
ProvencaleLeGaulois Messages postés 48 Date d'inscription   Statut Membre Dernière intervention   -
Bonjour,

J'aimerais savoir comment afficher une chaîne de caractères (caractère par caractère), c'est-à-dire afficher un char dans un JTextField puis afficher l'autre après 2 seconds par exemple ?

Voici mon code
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                         
 
   String s = jTextField4.getText(), s1 = "";
   String str = "";
   int L = s.length();
   int x = 1500;
 
   for (int i=0; i< L; i++) 
   {
        char prem = s.charAt(i);
        str= str + prem;
        x = x + 2000;
        final Thread th4 = new Thread (new  Runnable() {
            public void run() {
                try {
                    Thread.sleep(x);
                } catch (InterruptedException ex) {                 
                }
            }
        });
        th4.start();
 
        //jLabel32.setForeground(Color.BLUE);
 
        s1 = s1.concat(str);
        jTextField3.setText(s1);
    }
}


Quelqu'un saurait-il m'indiquer comment résoudre ce problème ?

Merci d'avance pour votre aide.

1 réponse

  1. ProvencaleLeGaulois Messages postés 48 Date d'inscription   Statut Membre Dernière intervention   6
     
    Bonjour,

    Je pense que tu n'es pas loin du but.

    Si tu remplaces :
            x = x + 2000;
            final Thread th4 = new Thread (new  Runnable() {
                public void run() {
                    try {
                        Thread.sleep(x);
                    } catch (InterruptedException ex) {                 
                    }
                }
            });
            th4.start();
    


    Par :
                    try {
                        Thread.sleep(2000);
                    } catch (InterruptedException ex) {                 
                    }
    


    Ça devrait fonctionner.

    A+
    0