Bonjour,
j'essaie d'arreter un thread via un mouselistener.
Le problème est qu'il reste un parti du programme actif lorsque je l'arrete. J'ai très certainement fais un bourde sur l'utilisation du thread mais j'arrive pas à trouver où...

code du gestionnaire de l'appli:
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
 
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
 
import java.util.LinkedList;
import java.util.List;
 
import javax.media.Time;
 
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;
 
public class GestBorne implements Runnable{
	private ObjDiaporama		diaporama=null;
	private List<ObjDiapo> 		listDiapo=null;
	private String				fichier="diaporama.xml";
	private IHMVisu				ihm=null;
	private Thread				th=null;
	private List<PanelVisu> 	listPanel=null;
	private PanelVisu			panel=null;
	private long				duree=0;
	private boolean 			visu=true;
	private FileInputStream 	fis=null;
	private XStream				xstream=null;
 
	public static void main(String args[]){
		new GestBorne();
	}
 
	public GestBorne(){
		diaporama=this.chargerDiaporama();
		listDiapo=diaporama.getListDiapo();
		th=new Thread(this);
		listPanel=this.chargerListpanel(diaporama);
		ihm=new IHMVisu(this);
		this.th.start();
	}
 
	@SuppressWarnings("static-access")
	@Override
	public void run() {
		while(visu){
			if(!(diaporama.equals(this.chargerDiaporama()))){
				diaporama=this.chargerDiaporama();
				listPanel=this.chargerListpanel(diaporama);
			}
			for(int cpt=0;cpt<listPanel.size();cpt++){
				if(visu){
					panel=listPanel.get(cpt);
					ihm.setContentPane(panel);
					ihm.validate();
					duree=panel.getDuree()*1000;
					try {
						if(panel!=null){
							if(panel.getClass().equals(PanelMedia.class)){
								((PanelMedia) panel).getPlayer().setMediaTime(new Time (0));
								((PanelMedia) panel).getPlayer().start();
							}
							this.th.sleep(duree);
							if(panel.getClass().equals(PanelMedia.class)){
								((PanelMedia) panel).getPlayer().stop();						
							}
						}
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
				}else{
					cpt=listPanel.size();
				}
			}
		}
		this.listDiapo=null;
		this.listPanel=null;
		this.th=null;
		this.ihm=null;
	}
 
	private ObjDiaporama chargerDiaporama(){
		ObjDiaporama diaporamaCharger=null;
		try {
			fis=new FileInputStream(new File(fichier));
			xstream = new XStream(new DomDriver());
			try{
				diaporamaCharger=(ObjDiaporama) xstream.fromXML(fis);
				listDiapo=diaporamaCharger.getListDiapo();
			}finally{
				fis.close();
			}
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}catch(IOException ioe){
			ioe.printStackTrace();
		}
		return diaporamaCharger;
	}
 
	private List<PanelVisu> chargerListpanel(ObjDiaporama diaporamaACharger){
		List<PanelVisu> list=new LinkedList<PanelVisu>();
		ObjDiapo diapoCharger=null;
		for(int cpt=0;cpt<diaporamaACharger.getListDiapo().size();cpt++){
			diapoCharger = diaporamaACharger.getListDiapo().get(cpt);
			if(diapoCharger.getType().compareTo("Page Web")==0){
				list.add(new PanelHTML(diapoCharger));
			}else if(diapoCharger.getType().compareTo("Video")==0){
				list.add(new PanelMedia(diapoCharger));
			}else if(diapoCharger.getType().compareTo("Images")==0){
				list.add(new PanelImage(diapoCharger));
			}
		}
		return list;
	}
 
	public synchronized void setVisu(boolean b) {
		visu=b;
	}
}
Code de l'interface graphique:
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
 
import java.awt.BorderLayout;
import java.awt.Toolkit;
import java.awt.event.MouseEvent;
 
import javax.swing.JFrame;
import javax.swing.JPanel;
 
@SuppressWarnings("serial")
public class IHMVisu extends JFrame {
	private GestBorne 		gestionnaire=null;
	private IHMListener 	ecouteur=null;
	private JPanel 			jContentPane=null;
 
	public IHMVisu(GestBorne gest){
		super();
		this.gestionnaire=gest;
		this.setUndecorated(true);
		this.setSize(Toolkit.getDefaultToolkit().getScreenSize());
		this.setContentPane(this.getJContentPane());
		this.addMouseListener(this.chargerListener());
		this.setVisible(true);
	}
 
	private IHMListener chargerListener() {
		if(ecouteur==null){
			ecouteur=new IHMListenerAdapter(){
				@Override
				public void mouseClicked(MouseEvent e){
					IHMVisu.this.gestionnaire.setVisu(false);
					IHMVisu.this.gestionnaire=null;
					IHMVisu.this.dispose();
				}
			};
		}
		return ecouteur;
	}
 
	private JPanel getJContentPane() {
		if(jContentPane==null){
			jContentPane=new JPanel();
			jContentPane.setLayout(new BorderLayout());
		}
		return jContentPane;
	}
}
Merci d'avance!