résolution bugs
This commit is contained in:
parent
e38338000f
commit
dd907d3da6
17 changed files with 75 additions and 17 deletions
|
@ -11,7 +11,7 @@
|
|||
<attribute name="module" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="lib" path="C:/Users/elise/OneDrive/Bureau/ELISE/INSA/4A/POO COO/java-json.jar">
|
||||
<classpathentry kind="lib" path="lib/java-json.jar">
|
||||
<attributes>
|
||||
<attribute name="module" value="true"/>
|
||||
</attributes>
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
chatGit/lib/java-json.jar
Normal file
BIN
chatGit/lib/java-json.jar
Normal file
Binary file not shown.
|
@ -6,6 +6,7 @@ import java.beans.PropertyChangeListener;
|
|||
import java.beans.PropertyChangeSupport;
|
||||
import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.Socket;
|
||||
import java.net.SocketException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
|
@ -139,9 +140,9 @@ public class Agent implements PropertyChangeListener{
|
|||
case 1 :
|
||||
MessagePseudo msgPseudo = (MessagePseudo) msg;
|
||||
boolean pseudoExist = Request.sendPseudo(msgPseudo.getPseudo(), "pseudoOK");
|
||||
if(pseudoExist) {
|
||||
if(!pseudoExist) {
|
||||
Contact newUser = new Contact(msgPseudo.getPseudo(), msgPseudo.getAddressSrc(), msgPseudo.getPortSrc());
|
||||
Request.sendUser(msgPseudo.getPseudo(), msgPseudo.getAddressSrc().toString(), Integer.toString(msgPseudo.getPortSrc()), "addUser");
|
||||
//Request.sendUser(msgPseudo.getPseudo(), msgPseudo.getAddressSrc().toString(), Integer.toString(msgPseudo.getPortSrc()), "addUser");
|
||||
//list.addContact(newUser);
|
||||
if(FenetreMenu.ouvert) {
|
||||
FenetreMenu.getCb().addItem(newUser.getPseudo());
|
||||
|
@ -154,7 +155,16 @@ public class Agent implements PropertyChangeListener{
|
|||
if(!pseudoExiste){
|
||||
Request.sendDeconnexion(Integer.toString(messageDeconnexion.getId()),messageDeconnexion.getPseudo(), "deconnexion");
|
||||
FenetreMenu.getCb().removeItem(messageDeconnexion.getPseudo());
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
//fermeture de la fenetre chat le user et la personne qui se deconnecte
|
||||
if(FenetreChat.isOuvert()&&FenetreChat.getDest().getPseudo().equals(messageDeconnexion.getPseudo())) {
|
||||
FenetreChat.fermer();
|
||||
}
|
||||
|
||||
case 3 :
|
||||
MessagePseudo messageNewPseudo = (MessagePseudo) msg;
|
||||
//Contact contact = list.findContact(messageNewPseudo.getPseudo());
|
||||
|
@ -276,7 +286,7 @@ public class Agent implements PropertyChangeListener{
|
|||
boolean isNotOnList = Request.sendPseudo(destPseudo, "pseudoOK");
|
||||
if(!isNotOnList) {
|
||||
Contact dest = Request.getUser(destPseudo, "getUser");
|
||||
TCPChat connexionTCP = new TCPChat(user, destId);
|
||||
TCPChat connexionTCP = new TCPChat(dest, destId);
|
||||
listTCPDeg.add(connexionTCP);
|
||||
connexionTCP.addPropertyChangeListener(this);
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ import java.awt.event.WindowEvent;
|
|||
import java.beans.PropertyChangeEvent;
|
||||
import java.beans.PropertyChangeListener;
|
||||
import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
import java.sql.SQLException;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
|
@ -28,11 +29,11 @@ import server.Request;
|
|||
|
||||
import java.awt.*;
|
||||
|
||||
public class FenetreChat extends JFrame {
|
||||
public class FenetreChat extends JFrame implements PropertyChangeListener{
|
||||
|
||||
JFrame frame;
|
||||
static JFrame frame;
|
||||
Agent agent;
|
||||
Contact dest; //destinataire du message
|
||||
static Contact dest; //destinataire du message
|
||||
Contact user; //utilisateur
|
||||
|
||||
WindowAdapter wa;
|
||||
|
@ -45,11 +46,22 @@ public class FenetreChat extends JFrame {
|
|||
|
||||
public FenetreChat(Agent agent, String userString) throws IOException {
|
||||
FenetreChat.ouvert=true;
|
||||
|
||||
this.frame = new JFrame("Fenetre Chat avec "+ userString);
|
||||
this.agent = agent;
|
||||
this.user = agent.getUser();
|
||||
//this.dest = agent.getList().findContact(userString);
|
||||
this.dest = Request.getUser(userString, "getUser");
|
||||
|
||||
InetAddress adr = dest.getAddress();
|
||||
TCPChat t=null;
|
||||
for(TCPChat tcp : agent.getListeTCPChat()) {
|
||||
if(tcp.getSocket().getInetAddress().equals(adr)) {
|
||||
t=tcp;
|
||||
}
|
||||
}
|
||||
t.addPropertyChangeListener(this);
|
||||
|
||||
this.frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
|
||||
|
||||
this.frame.setSize(new Dimension(400, 400));
|
||||
|
@ -228,9 +240,40 @@ public class FenetreChat extends JFrame {
|
|||
}
|
||||
}
|
||||
|
||||
public void propertyChange(PropertyChangeEvent evt) {
|
||||
switch(evt.getPropertyName()){
|
||||
case "deconnexion" :
|
||||
System.out.println("Je suis dans deconnexion");
|
||||
InetAddress adr = dest.getAddress();
|
||||
TCPChat t=null;
|
||||
for(TCPChat tcp : agent.getListeTCPChat()) {
|
||||
if(tcp.getSocket().getInetAddress().equals(adr)) {
|
||||
t=tcp;
|
||||
}
|
||||
}
|
||||
try {
|
||||
t.getSocket().close();
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
agent.getListeTCPChat().remove(t);
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isOuvert() {
|
||||
return ouvert;
|
||||
}
|
||||
|
||||
public static void fermer() {
|
||||
frame.dispose();
|
||||
}
|
||||
|
||||
public static Contact getDest() {
|
||||
return dest;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -142,9 +142,10 @@ public class FenetreMenu {
|
|||
JScrollPane scrollPane = new JScrollPane(ta);
|
||||
|
||||
String users = Request.actifs("actifs");
|
||||
String users2 = users.replaceAll("\\s", "\n");
|
||||
//String users = agent.getList().actifUsers();
|
||||
Vector<String> v = new Vector<String>();
|
||||
for(String pseudo : users.split("\n")) {
|
||||
for(String pseudo : users2.split("\n")) {
|
||||
v.add(pseudo);
|
||||
}
|
||||
|
||||
|
|
|
@ -30,8 +30,9 @@ public class MessageChat extends Message{
|
|||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
return message+" "+dateToString();
|
||||
}
|
||||
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
|
|
|
@ -48,6 +48,7 @@ public class TCPChat extends Thread{
|
|||
|
||||
public void addPropertyChangeListener(PropertyChangeListener pcl) {
|
||||
this.support.addPropertyChangeListener("Msg TCP Recu", pcl);
|
||||
this.support.addPropertyChangeListener("deconnexion",pcl);
|
||||
}
|
||||
|
||||
|
||||
|
@ -59,17 +60,19 @@ public class TCPChat extends Thread{
|
|||
|
||||
while(true) {
|
||||
try {
|
||||
String input = in.readLine();
|
||||
MessageChat msgRecu = new MessageChat(this.socket.getInetAddress(), this.socket.getLocalAddress(), this.socket.getPort(), this.socket.getLocalPort(), 0, input);
|
||||
listeMessagesRecu.add(msgRecu);
|
||||
//System.out.println("fire msg tcp recu");
|
||||
this.support.firePropertyChange("Msg TCP Recu", true, false);
|
||||
//if (!msgRecu.getMessage().equals(null)) {
|
||||
String input = in.readLine();
|
||||
MessageChat msgRecu = new MessageChat(this.socket.getInetAddress(), this.socket.getLocalAddress(), this.socket.getPort(), this.socket.getLocalPort(), 0, input);
|
||||
listeMessagesRecu.add(msgRecu);
|
||||
//System.out.println("fire msg tcp recu");
|
||||
this.support.firePropertyChange("Msg TCP Recu", true, false);
|
||||
//if (!msgRecu.getMessage().equals(null)) {
|
||||
//System.out.println("Message reçu : "+msgRecu.getMessage() );
|
||||
//}
|
||||
//}
|
||||
} catch (IOException e) {
|
||||
this.support.firePropertyChange("deconnexion",true,false);
|
||||
System.out.println("Création et read du in impossible");
|
||||
e.printStackTrace();
|
||||
break;
|
||||
//e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue