Bonjour,

j'ai un petit soucis, je voudrais lancer un Thread puis afficher toutes les deux secondes "données reçues".

J'arrive à lancer mon Thread mais j'ai du mal au niveau du timer...
Voici mon code :


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
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
 
import javax.swing.Timer;
 
 
/**
 * 
 */
 
/**
 * @author pf95227
 *
 */
public class ExperimentThread extends Thread{
 
	public void run(){
 
	System.out.println("on est dans le run");
 
	}
	public void timerStart(){
 
		ActionListener actionListener = new ActionListener() {
 
		      public void actionPerformed(ActionEvent actionEvent) {
		    	  System.out.println("thread lancé");
		      }
 
		    };
		    Timer timer = new Timer(50, actionListener);
		    timer.start();
 
 
 
	}
 
	/**
         * 
         */
	public ExperimentThread() {
		// TODO Auto-generated constructor stub
		System.out.println("start du thead");
	}
 
 
 
 
}