Quand on ferme l'interface, on ferme tout
This commit is contained in:
parent
fcb1ccf532
commit
f496eb89b1
1 changed files with 33 additions and 10 deletions
|
@ -4,14 +4,18 @@ import javax.swing.*;
|
|||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import controller.Controller;
|
||||
import model.RemoteUser;
|
||||
|
||||
public class Interface implements ActionListener {
|
||||
public class Interface extends JFrame implements ActionListener, WindowListener {
|
||||
|
||||
public Controller hisController;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L; //JFrame stuff
|
||||
|
||||
public static Controller hisController;
|
||||
|
||||
public JLabel Pseudolabel;
|
||||
public JTextField PseudotextField;
|
||||
|
@ -28,6 +32,14 @@ public class Interface implements ActionListener {
|
|||
|
||||
public Interface(Controller controller) {
|
||||
this.hisController = controller;
|
||||
this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
|
||||
this.addWindowListener(new java.awt.event.WindowAdapter() {
|
||||
@Override
|
||||
public void windowClosing(java.awt.event.WindowEvent e) {
|
||||
System.out.println("Window closing");
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
public Component createComponents() {
|
||||
|
@ -101,8 +113,6 @@ public class Interface implements ActionListener {
|
|||
}else {
|
||||
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)));
|
||||
//System.out.println("selectedUsernb: " + selectedUsernb); //Test pour voir si ça marche
|
||||
//TODO Utiliser ce selectedUsernb pour faire le lien avec openSession de Controller
|
||||
hisController.openSession(hisController.getMyUser().addChats(hisController.getMyUser().getRemoteUsersList().get(selectedUsernb)));
|
||||
|
||||
}
|
||||
|
@ -156,10 +166,17 @@ public class Interface implements ActionListener {
|
|||
JFrame.setDefaultLookAndFeelDecorated(true);
|
||||
|
||||
//Create and set up the window.
|
||||
JFrame frame = new JFrame("SwingApplication");
|
||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
|
||||
JFrame frame = new JFrame("Clavardage App");
|
||||
frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
|
||||
|
||||
frame.addWindowListener(new java.awt.event.WindowAdapter() {
|
||||
@Override
|
||||
public void windowClosing(java.awt.event.WindowEvent windowEvent) {
|
||||
System.out.println("GUI has been closed");
|
||||
hisController.interfaceRunning = false;
|
||||
System.exit(0);
|
||||
}
|
||||
});
|
||||
|
||||
Interface app = new Interface(controller);
|
||||
Component contents = app.createComponents();
|
||||
|
@ -172,7 +189,13 @@ public class Interface implements ActionListener {
|
|||
return app;
|
||||
}
|
||||
|
||||
|
||||
public void windowOpened(WindowEvent e) {} //Had to implement it for WindowListener
|
||||
public void windowActivated(WindowEvent e) {}
|
||||
public void windowIconified(WindowEvent e) {}
|
||||
public void windowDeiconified(WindowEvent e) {}
|
||||
public void windowDeactivated(WindowEvent e) {}
|
||||
public void windowClosed(WindowEvent e) {}
|
||||
public void windowClosing(WindowEvent e) {}
|
||||
|
||||
/*
|
||||
public static void main(String[] args) throws IOException {
|
||||
|
|
Loading…
Reference in a new issue