déconnexion + messages de connexion/déconnexion d'un utilisateur
This commit is contained in:
parent
6c0c3f8747
commit
88f3760164
2 changed files with 15 additions and 6 deletions
|
@ -1,10 +1,14 @@
|
||||||
package chat;
|
package chat;
|
||||||
public class Message {
|
|
||||||
|
import java.io.*;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
public class Message implements Serializable{
|
||||||
|
|
||||||
private String text;
|
private String text;
|
||||||
private String author;
|
private String author;
|
||||||
|
|
||||||
public Message(String in_text, String in_author)
|
public Message(String in_author, String in_text)
|
||||||
{
|
{
|
||||||
text = in_text;
|
text = in_text;
|
||||||
author = in_author;
|
author = in_author;
|
||||||
|
|
|
@ -107,14 +107,13 @@ class ReceiveThread extends Thread {
|
||||||
}
|
}
|
||||||
|
|
||||||
class ConnectionListenerThread extends Thread {
|
class ConnectionListenerThread extends Thread {
|
||||||
|
|
||||||
int port;
|
|
||||||
JTextArea displayArea;
|
JTextArea displayArea;
|
||||||
List<User> known_users;
|
List<User> known_users;
|
||||||
|
|
||||||
ConnectionListenerThread(List<User> in_known_users)
|
ConnectionListenerThread(List<User> in_known_users, JTextArea in_displayArea)
|
||||||
{
|
{
|
||||||
known_users = in_known_users;
|
known_users = in_known_users;
|
||||||
|
displayArea = in_displayArea;
|
||||||
}
|
}
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
|
@ -169,6 +168,8 @@ class ConnectionListenerThread extends Thread {
|
||||||
if(accepted)
|
if(accepted)
|
||||||
{
|
{
|
||||||
known_users.add(new User(username, clientAddress.getHostAddress()));
|
known_users.add(new User(username, clientAddress.getHostAddress()));
|
||||||
|
displayArea.append(username + " has joined the chat.\n");
|
||||||
|
displayArea.setCaretPosition(displayArea.getDocument().getLength());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -292,9 +293,13 @@ public class NetworkClient {
|
||||||
if(connected)
|
if(connected)
|
||||||
{
|
{
|
||||||
user.setName(username);
|
user.setName(username);
|
||||||
|
|
||||||
|
chatText.append(username + " has joined the chat.\n");
|
||||||
|
chatText.setCaretPosition(chatText.getDocument().getLength());
|
||||||
|
|
||||||
ReceiveThread t2 = new ReceiveThread(1237, chatText, known_users);
|
ReceiveThread t2 = new ReceiveThread(1237, chatText, known_users);
|
||||||
|
|
||||||
ConnectionListenerThread t3 = new ConnectionListenerThread(known_users);
|
ConnectionListenerThread t3 = new ConnectionListenerThread(known_users, chatText);
|
||||||
t2.start();
|
t2.start();
|
||||||
t3.start();
|
t3.start();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue