From 1d72027a3ae81966de45b1f39399d6dfaa5ad7a6 Mon Sep 17 00:00:00 2001 From: tgiraud Date: Fri, 18 Dec 2020 09:56:02 +0100 Subject: [PATCH] Interface avec fermeturre des chats --- .../Clavardage/src/view/Interface.java | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/Application/Clavardage/src/view/Interface.java b/Application/Clavardage/src/view/Interface.java index 7fd07d7..a6eb9cb 100644 --- a/Application/Clavardage/src/view/Interface.java +++ b/Application/Clavardage/src/view/Interface.java @@ -25,6 +25,7 @@ public class Interface extends JFrame implements ActionListener, WindowListener public JButton RemoteUserButton; public JComboBox RemoteUserbox; + public JButton CloseConversationButton; //Specifies the look and feel to use. Valid values: //null (use the default), "Metal", "System", "Motif", "GTK+" @@ -49,7 +50,7 @@ public class Interface extends JFrame implements ActionListener, WindowListener Pseudolabel = new JLabel("Your current username is: " + controller.getMyUser().getPseudo()); Pseudolabel.setLabelFor(PseudotextField); - RemoteUserButton = new JButton("Click here to get Remote User list"); //Remote user list setup + RemoteUserButton = new JButton("Click to get Remote User list"); //Remote user list setup RemoteUserButton.addActionListener(this); //Convert the Userlist to Pseudotab String[] pseudotab = new String[controller.getMyUser().getRemoteUsersList().size()]; @@ -60,6 +61,9 @@ public class Interface extends JFrame implements ActionListener, WindowListener RemoteUserbox.setEditable(true); RemoteUserbox.addActionListener(this); RemoteUserbox.setVisible(false); + CloseConversationButton = new JButton("Click to close active chat"); + CloseConversationButton.addActionListener(this); + CloseConversationButton.setVisible(false); MessagetextField = new JTextField(); //Messages setup MessagetextField.setColumns(10); @@ -81,6 +85,7 @@ public class Interface extends JFrame implements ActionListener, WindowListener pane.add(RemoteUserbox); pane.add(Messagelabel); pane.add(MessagetextField); + pane.add(CloseConversationButton); pane.setBorder(BorderFactory.createEmptyBorder( 30, //top 30, //left @@ -110,6 +115,11 @@ public class Interface extends JFrame implements ActionListener, WindowListener }else if(e.getSource() == RemoteUserButton) { //Shows remote user list RemoteUserbox.setVisible(true); + }else if(e.getSource() == CloseConversationButton) { + controller.askCloseSession(); + Messagelabel.setVisible(false); + MessagetextField.setVisible(false); + CloseConversationButton.setVisible(false); }else { // Choice in remote user list JComboBox cb = (JComboBox)e.getSource(); //Casts obscurs pour récupérer le numéro du user dans la liste @@ -121,6 +131,7 @@ public class Interface extends JFrame implements ActionListener, WindowListener Messagelabel.setText("Message:
"+history); MessagetextField.setVisible(true); Messagelabel.setVisible(true); + CloseConversationButton.setVisible(true); } } @@ -174,20 +185,16 @@ public class Interface extends JFrame implements ActionListener, WindowListener //Create and set up the window. JFrame frame = new JFrame("Clavardage App"); frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); - - - Interface app = new Interface(controller); Component contents = app.createComponents(); frame.getContentPane().add(contents, BorderLayout.CENTER); - + //Ends all running background tasks upon closing the window frame.addWindowListener(new java.awt.event.WindowAdapter() { @Override public void windowClosing(java.awt.event.WindowEvent windowEvent) { - System.out.println("GUI has been closed"); + System.out.println("Window has been closed"); app.controller.interfaceRunning = false; - System.exit(0); } });