Interface avec fermeturre des chats

This commit is contained in:
Theau Giraud 2020-12-18 09:56:02 +01:00
parent 21b447fe98
commit 1d72027a3a

View file

@ -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:<br>"+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);
}
});