diff --git a/Application/Clavardage/src/controller/Controller.java b/Application/Clavardage/src/controller/Controller.java index e715511..3d5c875 100644 --- a/Application/Clavardage/src/controller/Controller.java +++ b/Application/Clavardage/src/controller/Controller.java @@ -52,8 +52,8 @@ public class Controller { * - notification aux autres utilisateurs actifs *

*/ - private Controller(int portUDPsend,int portUDPlistening,int portTCP) { - this.histoire= new Historique(); + private Controller(int portUDPsend,int portUDPlistening,int portTCP,Historique histoire) { + this.histoire= histoire; InetAddress addIP = null; try @@ -97,7 +97,8 @@ public class Controller { * - notification aux autres utilisateurs actifs *

*/ - 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 { @@ -361,7 +362,8 @@ public class Controller { Calendar date1=Calendar.getInstance(); date = new Date(); date1.setTime(date); - dateString=date1.toString(); + dateString=date1.toString(); + this.getHistory().saveMessage(getMyUser(), c.getRemoteUser(),message ,dateString ); /* System.out.println(this.getHistory()); @@ -376,8 +378,8 @@ public class Controller { //this.getHistory().saveMessage(this.myUser, c.getRemoteUser(),message ,dateString); // Envoie du message (avec la date) - DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); - out.println(dateFormat.format(date)); + //DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); + out.println(dateString); out.println(message); } @@ -490,14 +492,15 @@ public class Controller { System.out.println("start program"); Historique histoire=new Historique(); + /** Création des utilisateurs **/ // REMOTEUSER_1 - MIKE - Controller ctr2 = new Controller(31012,portUDPlistening_remoteUsr2,31022,"Mike"); + Controller ctr2 = new Controller(31012,portUDPlistening_remoteUsr2,31022,"Mike",histoire); // REMOTEUSER_2 - ALICE - Controller ctr3 = new Controller(31013,portUDPlistening_remoteUsr3,31023,"Alice"); + Controller ctr3 = new Controller(31013,portUDPlistening_remoteUsr3,31023,"Alice",histoire); // LOCAL USER - Controller ctr1 = new Controller(31011,31001,31021); + Controller ctr1 = new Controller(31011,31001,31021,histoire); /** Création de l'interface graphique **/ ctr1.hisView=Interface.createAndShowGUI(ctr1); diff --git a/Application/Clavardage/src/controller/Historique.java b/Application/Clavardage/src/controller/Historique.java index ec5a086..ca0ca85 100644 --- a/Application/Clavardage/src/controller/Historique.java +++ b/Application/Clavardage/src/controller/Historique.java @@ -109,7 +109,7 @@ public class Historique { this.bdd.close(); } //MAIN - public void Historique() { + public Historique() { this.bdd=new model.Database(); System.out.println("coucoudb"); diff --git a/Application/Clavardage/src/model/Database.java b/Application/Clavardage/src/model/Database.java index 691de11..a95cd7f 100644 --- a/Application/Clavardage/src/model/Database.java +++ b/Application/Clavardage/src/model/Database.java @@ -22,7 +22,7 @@ public class Database { } - public void Database() { + public Database() { try { Class.forName("java.sql.Driver"); System.out.println("coucou"); @@ -47,15 +47,15 @@ public class Database { } int nb_changed_rows=0; +// try { +// nb_changed_rows = statement.executeUpdate("CREATE DATABASE base"); +// System.out.println("coucou"); +// } catch (SQLException e) { +// System.out.println("base de données pas établit"); +// e.printStackTrace(); +// } try { - nb_changed_rows = statement.executeUpdate("CREATE DATABASE base"); - System.out.println("coucou"); - } catch (SQLException e) { - System.out.println("base de données pas établit"); - e.printStackTrace(); - } - try { - nb_changed_rows = statement.executeUpdate("USE base"); + nb_changed_rows = statement.executeUpdate("USE tp_servlet_003"); System.out.println("coucou"); } catch (SQLException e) { System.out.println("use base pas établit");