déconnexion + messages de connexion/déconnexion d'un utilisateur

This commit is contained in:
Metatheria 2021-01-05 17:29:37 +01:00
parent 6c0c3f8747
commit 88f3760164
2 changed files with 15 additions and 6 deletions

View file

@ -1,10 +1,14 @@
package chat;
public class Message {
import java.io.*;
import java.util.*;
public class Message implements Serializable{
private String text;
private String author;
public Message(String in_text, String in_author)
public Message(String in_author, String in_text)
{
text = in_text;
author = in_author;

View file

@ -107,14 +107,13 @@ class ReceiveThread extends Thread {
}
class ConnectionListenerThread extends Thread {
int port;
JTextArea displayArea;
List<User> known_users;
ConnectionListenerThread(List<User> in_known_users)
ConnectionListenerThread(List<User> in_known_users, JTextArea in_displayArea)
{
known_users = in_known_users;
displayArea = in_displayArea;
}
public void run()
{
@ -169,6 +168,8 @@ class ConnectionListenerThread extends Thread {
if(accepted)
{
known_users.add(new User(username, clientAddress.getHostAddress()));
displayArea.append(username + " has joined the chat.\n");
displayArea.setCaretPosition(displayArea.getDocument().getLength());
}
else
{
@ -292,9 +293,13 @@ public class NetworkClient {
if(connected)
{
user.setName(username);
chatText.append(username + " has joined the chat.\n");
chatText.setCaretPosition(chatText.getDocument().getLength());
ReceiveThread t2 = new ReceiveThread(1237, chatText, known_users);
ConnectionListenerThread t3 = new ConnectionListenerThread(known_users);
ConnectionListenerThread t3 = new ConnectionListenerThread(known_users, chatText);
t2.start();
t3.start();
}