ajout selection remoteuser

This commit is contained in:
Alexandre Gonzalvez 2020-12-16 12:22:58 +01:00
parent 89b3f1aa97
commit e748951c79
2 changed files with 70 additions and 53 deletions

View file

@ -363,7 +363,7 @@ public class Controller {
date = new Date(); date = new Date();
date1.setTime(date); date1.setTime(date);
dateString=date1.toString(); dateString=date1.toString();
this.getHistory().saveMessage(getMyUser(), c.getRemoteUser(),message ,dateString ); //this.getHistory().saveMessage(getMyUser(), c.getRemoteUser(),message ,dateString );
/* /*
System.out.println(this.getHistory()); System.out.println(this.getHistory());
@ -378,7 +378,7 @@ public class Controller {
//this.getHistory().saveMessage(this.myUser, c.getRemoteUser(),message ,dateString); //this.getHistory().saveMessage(this.myUser, c.getRemoteUser(),message ,dateString);
// Envoie du message (avec la date) // Envoie du message (avec la date)
//DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
out.println(dateString); out.println(dateString);
out.println(message); out.println(message);
} }
@ -503,9 +503,11 @@ public class Controller {
Controller ctr1 = new Controller(31011,31001,31021,histoire); Controller ctr1 = new Controller(31011,31001,31021,histoire);
/** Création de l'interface graphique **/ /** Création de l'interface graphique **/
Boolean interfaceRunning = true;
ctr1.hisView=Interface.createAndShowGUI(ctr1); ctr1.hisView=Interface.createAndShowGUI(ctr1);
/** Simulation of a session **/ /** Simulation of a session **/
// SELECT REMOTE USER // SELECT REMOTE USER
Chat chatwithrm0 = ctr1.myUser.addChats(ctr1.myUser.getRemoteUsersList().get(0)); Chat chatwithrm0 = ctr1.myUser.addChats(ctr1.myUser.getRemoteUsersList().get(0));
// AFFICHAGE REMOTE USER CHOISIE // AFFICHAGE REMOTE USER CHOISIE
@ -518,16 +520,24 @@ public class Controller {
ctr1.sendMsg(new Msg_Text(ctr1.myUser.getAddIP(),"end"), chatwithrm0); ctr1.sendMsg(new Msg_Text(ctr1.myUser.getAddIP(),"end"), chatwithrm0);
ctr1.closeSession(chatwithrm0); ctr1.closeSession(chatwithrm0);
/** Unused function **/ /** Unused function **/
// MANUAL SELECTION OF ACTIVE USER // MANUAL SELECTION OF ACTIVE USER
//ctr1.selectActiveUser(); //ctr1.selectActiveUser();
// CHANGE USER NICKNAME // CHANGE USER NICKNAME
//ctr1.changePseudo(); //ctr1.changePseudo();
/*
while(interfaceRunning) {
}*/
/** Close thread and socket **/ /** Close thread and socket **/
// SLEEP 5 SEC // SLEEP 20 SEC
System.out.println("Sleep mode for 5 seconds ..."); System.out.println("Sleep mode for 20 seconds ...");
Thread.sleep(5000); Thread.sleep(20000);
// REMOTEUSER_1 - MIKE // REMOTEUSER_1 - MIKE
ctr2.myUser.closeAllRemainingChatSocket(); ctr2.myUser.closeAllRemainingChatSocket();
ctr2.tcp_connect_thread.close(); ctr2.tcp_connect_thread.close();

View file

@ -101,8 +101,10 @@ public class Interface implements ActionListener {
}else { }else {
JComboBox cb = (JComboBox)e.getSource(); //Casts obscurs pour récupérer le numéro du user dans la liste JComboBox cb = (JComboBox)e.getSource(); //Casts obscurs pour récupérer le numéro du user dans la liste
int selectedUsernb = Integer.parseInt(String.valueOf(((String) cb.getSelectedItem()).charAt(1))); int selectedUsernb = Integer.parseInt(String.valueOf(((String) cb.getSelectedItem()).charAt(1)));
System.out.println("selectedUsernb: " + selectedUsernb); //Test pour voir si ça marche //System.out.println("selectedUsernb: " + selectedUsernb); //Test pour voir si ça marche
//TODO Utiliser ce selectedUsernb pour faire le lien avec openSession de Controller //TODO Utiliser ce selectedUsernb pour faire le lien avec openSession de Controller
hisController.openSession(hisController.getMyUser().addChats(hisController.getMyUser().getRemoteUsersList().get(selectedUsernb)));
} }
} }
@ -157,6 +159,8 @@ public class Interface implements ActionListener {
JFrame frame = new JFrame("SwingApplication"); JFrame frame = new JFrame("SwingApplication");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Interface app = new Interface(controller); Interface app = new Interface(controller);
Component contents = app.createComponents(); Component contents = app.createComponents();
frame.getContentPane().add(contents, BorderLayout.CENTER); frame.getContentPane().add(contents, BorderLayout.CENTER);
@ -167,6 +171,9 @@ public class Interface implements ActionListener {
return app; return app;
} }
/* /*
public static void main(String[] args) throws IOException { public static void main(String[] args) throws IOException {
//Schedule a job for the event-dispatching thread: //Schedule a job for the event-dispatching thread: