diff --git a/src/GraphiquePackage/FichAccueil.java b/src/GraphiquePackage/FichAccueil.java index 7e831d2..c57d6de 100644 --- a/src/GraphiquePackage/FichAccueil.java +++ b/src/GraphiquePackage/FichAccueil.java @@ -23,21 +23,12 @@ public class FichAccueil extends javax.swing.JFrame { public FichAccueil() { - exitSystem(); + initComponents(); } - public void exitSystem(){ - this.addWindowListener(new java.awt.event.WindowAdapter() { - @Override - public void windowClosing(java.awt.event.WindowEvent e) { - Main.user.sendMessageUDP("quita"); - System.exit(0); - } - }); - } - + /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always diff --git a/src/GraphiquePackage/FichCom.java b/src/GraphiquePackage/FichCom.java index c4826da..7c2370e 100644 --- a/src/GraphiquePackage/FichCom.java +++ b/src/GraphiquePackage/FichCom.java @@ -23,6 +23,21 @@ public FichCom(java.awt.Dialog parent, boolean modal, int port ) { super(parent, modal); initComponents(); portDest = port ; + + exitSystem(); + + } + + + public void exitSystem(){ + this.addWindowListener(new java.awt.event.WindowAdapter() { + @Override + public void windowClosing(java.awt.event.WindowEvent e) { + Main.user.sendMessageUDP("quito"); + System.out.println("jai send le msg" ); + System.exit(0); + } + }); } /** diff --git a/src/GraphiquePackage/FichMenu.java b/src/GraphiquePackage/FichMenu.java index 4da6412..97c4a9a 100644 --- a/src/GraphiquePackage/FichMenu.java +++ b/src/GraphiquePackage/FichMenu.java @@ -32,7 +32,20 @@ public FichMenu(FichAccueil parent, boolean modal) { ThreadPrintListUser threadPrint = new ThreadPrintListUser("thread print"); threadPrint.start(); + exitSystem(); } + + public void exitSystem(){ + this.addWindowListener(new java.awt.event.WindowAdapter() { + @Override + public void windowClosing(java.awt.event.WindowEvent e) { + Main.user.sendMessageUDP("quita"); + System.out.println("jai send le msg" ); + System.exit(0); + } + }); + } + public static void setListUser(String liste){ listUser.setText(liste); diff --git a/src/SourcePackage/ThreadReceive.java b/src/SourcePackage/ThreadReceive.java index 61bb39a..09caaa2 100644 --- a/src/SourcePackage/ThreadReceive.java +++ b/src/SourcePackage/ThreadReceive.java @@ -43,6 +43,10 @@ public static void receiveMessage() throws IOException { //UDP : boucle qui re Main.user.removeUserList(info[1]);//mettre a jour sa liste : l'enlever } + else if(recvStr.contains("quito")){ + Main.user.removeSocketList(recvPacket.getPort()); + } + else { if( !Main.user.belongList(recvStr)){ InetAddress addr = recvPacket.getAddress(); diff --git a/src/SourcePackage/User.java b/src/SourcePackage/User.java index dc8b113..e92a53d 100644 --- a/src/SourcePackage/User.java +++ b/src/SourcePackage/User.java @@ -154,9 +154,24 @@ public void setListUser(String pseudo, String ipPort){ } public void removeUserList(String pseudo1){ + System.out.println("J'ai remove !!! "); this.listUser.remove(pseudo1); } + public void removeSocketList(int port){ + System.out.println("J'ai fermé la co !!! "); + System.out.println("Etat du socket avant : "+ listSocket.get(port).isConnected()); + + try { + listSocket.get(port).close(); + } catch (IOException ex) { + Logger.getLogger(User.class.getName()).log(Level.SEVERE, null, ex); + } + System.out.println("Etat du socket apres : "+ listSocket.get(port).isConnected()); + + this.listSocket.remove(port); + } + public boolean belongList(String pseudo){ if (listUser.containsKey(pseudo)){ return true;