Bonsoir,

Voila j'ai fait une petite application de tchat, pour l'instant ça marche bien mais j'ai remarqué un petit soucis, lorsque je démarre mon application j'ai le processeur qui monte à fond et c'est cette classe qui me fais ça:

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
package client;
 
import java.io.IOException;
import java.io.PrintWriter;
import java.net.Socket;
 
import javax.swing.JOptionPane;
 
public class Envoie implements Runnable {
	private Socket socket;
    private PrintWriter out;
    private Thread t;
    private static boolean deco = false;
    private static boolean echec = false;
    private String name;
    private InterfaceGraphique fenetre;
    private String texte;
    private Client client;
 
    	public Envoie (InterfaceGraphique fenetre, Client client) {
    		this.fenetre = fenetre;
    		this.client = client;
    	}
 
		@Override
		public void run () {
	    	String fromUser = "";
	    	try {
		    	while (true) {
			    	// envoie
		    		fromUser = this.texte;
		    		if (fromUser != null && fromUser.length () != 0) {
		    			if (this.out != null && !fromUser.equals ("connect")) {
				    		this.out.println (this.name + ":" + fromUser);
				    	}
		    			if (fromUser.equals ("deco")) {
		    				if (Envoie.deco) {
				    			JOptionPane.showMessageDialog (this.fenetre, "Vous etes deja deconnecte du serveur");
				    		}
				    		else {
				    			this.socket.close ();
				    			Envoie.deco = true;
				    		}
 
		    			}
				    	else if (fromUser.equals ("quitter")) {
							this.socket.close ();
							this.out.close ();
				    		break;
						}
				    	else if (fromUser.equals ("connect")) {
						    if (Envoie.deco) {
						    	this.client.connection ();
						    	this.connection ();
						    }
						    else {
						    	JOptionPane.showMessageDialog (this.fenetre, "Vous etes deja connecte au serveur");
						    }
						}
						fromUser = null;
						this.texte = null;
			    	}
		    	}
	    	}
	    	catch (IOException e) {
	    		JOptionPane.showMessageDialog (this.fenetre, "Erreur de I/O avec l'hote dans la classe Envoie");
			}
		}
 
		public void connection () {
	    	try {
	    		if (!Envoie.echec) {
	    			this.socket = this.client.getSocket ();
		    		this.out = new PrintWriter (this.socket.getOutputStream (), true);
		    		if (!Envoie.deco) {
		            	this.t = new Thread (this);
			            this.t.start ();
		            }
		            if (this.out != null) {
			    		this.out.println (this.name);
			    	}
		    		Envoie.deco = false;
	    		}
	        } 
	    	catch (IOException e) {
	            JOptionPane.showMessageDialog (this.fenetre, "Soucis d'I/O avec l'hote");
	        }
	    	catch (NullPointerException e) {
	    		JOptionPane.showMessageDialog (this.fenetre, "Pointeur null reçu");
	    	}  
	    }
 
		public void setName (String name) {
	    	this.name = name;
	    }
 
	    public void setTexte (String texte) {
	    	this.texte = texte;
	    }
 
	    public static void deconection () {
	    	Envoie.deco = true;
	    }
 
	    public static void echecConnection (boolean echec) {
	    	Envoie.echec = echec;
	    }
 
	    public static boolean getDeconnection () {
	    	return Envoie.deco;
	    }
}
Cela doit très certainement être ma boucle mais je ne vois pas pourquoi Si quelqu'un a une solution je l'en remercie d'avance