This commit is contained in:
LMAGallois 2020-12-15 22:14:13 +01:00
parent 27d44abacf
commit e19bc4b45c
2 changed files with 25 additions and 9 deletions

View file

@ -10,6 +10,7 @@ import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import javax.swing.JOptionPane;
@ -29,7 +30,7 @@ public class Controller {
private ListeningThreadUDP udp_connect_thread;
private ListeningThreadTCPConnection tcp_connect_thread;
private ArrayList<ListeningThreadTCPChat> tcp_chats_threads = new ArrayList<ListeningThreadTCPChat>(); // listes des utilisateurs actifs
private Historique histoire;
/**
* Constructor of Controller
* @parametres
@ -45,7 +46,8 @@ public class Controller {
* - notification aux autres utilisateurs actifs
* </p>
*/
private Controller(int portUDPsend,int portUDPlistening,int portTCP) {
private Controller(int portUDPsend,int portUDPlistening,int portTCP,Historique histoire) {
this.histoire=histoire;
InetAddress addIP = null;
try
{
@ -88,7 +90,8 @@ public class Controller {
* - notification aux autres utilisateurs actifs
* </p>
*/
private Controller(int portUDPsend,int portUDPlistening,int portTCP,String pseudo) {
private Controller(int portUDPsend,int portUDPlistening,int portTCP,String pseudo,Historique histoire) {
this.histoire=histoire;
InetAddress addIP = null;
try
{
@ -127,7 +130,9 @@ public class Controller {
public ArrayList<ListeningThreadTCPChat> getTcp_chats_threads() {
return tcp_chats_threads;
}
public Historique getHistory() {
return histoire;
}
/*** SETTERS ***/
public void setMyUser(LocalUser myUser) {
this.myUser = myUser;
@ -144,7 +149,9 @@ public class Controller {
public void setTcp_chats_threads(ArrayList<ListeningThreadTCPChat> tcp_chats_threads) {
this.tcp_chats_threads = tcp_chats_threads;
}
public void setHistory(Historique histoire) {
this.histoire=histoire;
}
/**
@ -347,10 +354,18 @@ public class Controller {
e.printStackTrace();
}
String input;
String dateString;
Date date;
Calendar date1=Calendar.getInstance();
String s2 = (this.myUser.getPseudo()+" reçoit un message");
try {
while (!(input=in.readLine()).equals("end")) {
System.out.print("client_recoit:"+input);
date=new Date();
date1.setTime(date);
dateString=date1.toString();
this.getHistory().saveMessage(this.getMyUser(), getMyUser().getRemoteUsersList().get(index),input ,dateString );
}
} catch (IOException e) {
// TODO Auto-generated catch block
@ -424,9 +439,10 @@ public class Controller {
/*************************************************************************************************************************/
public static void main(String[] args) throws IOException, InterruptedException {
Controller ctr2 = new Controller(12226,portUDPlistening_remoteUsr2,22222,"Mike");
Controller ctr3 = new Controller(12224,portUDPlistening_remoteUsr3,22223,"Alice");
Controller ctr1 = new Controller(12225,20001,22221); // Notre utilisateur local
Historique histoire=new Historique();
Controller ctr2 = new Controller(12226,portUDPlistening_remoteUsr2,22222,"Mike",histoire);
Controller ctr3 = new Controller(12224,portUDPlistening_remoteUsr3,22223,"Alice",histoire);
Controller ctr1 = new Controller(12225,20001,22221,histoire); // Notre utilisateur local
// Création de l'interface
ctr1.hisView=Interface.createAndShowGUI(ctr1);

View file

@ -62,7 +62,7 @@ public class Historique {
}
}
public String retrieveMessage(model.User user1, model.RemoteUser user2) throws SQLException {
public String retrieveMessage(model.LocalUser user1, model.RemoteUser user2) throws SQLException {
this.setRSSent(this.bdd.getStatement().executeQuery("SELECT"+user1.getIPcode()+","+user2.getIPcode()+",? ,? FROM table"));
this.setRSReceived(this.bdd.getStatement().executeQuery("SELECT"+user2.getIPcode()+","+user1.getIPcode()+",?, ? FROM table"));
//this.setRSMDSent(this.getRSSent().getMetaData());