diff --git a/module-b/src/main/java/fr/unantes/sce/trivial/view/Window.java b/module-b/src/main/java/fr/unantes/sce/trivial/view/Window.java index e61ddca54c7e8b5cb34001604452eadf7bde799b..3537fbb75e92e84b1da32c27218c879a1c36e35b 100644 --- a/module-b/src/main/java/fr/unantes/sce/trivial/view/Window.java +++ b/module-b/src/main/java/fr/unantes/sce/trivial/view/Window.java @@ -23,7 +23,8 @@ import fr.unantes.sce.trivial.utility.Audio; */ public class Window extends JFrame { - + + public static final String INFORMATION = "Information"; private static final long serialVersionUID = 1L; private Audio son; boolean activer = true; // Son activer/d�sactiver @@ -214,34 +215,29 @@ public class Window extends JFrame { jmiLogout = new JMenuItem("Logout"); jmiLogout.setEnabled(false); - jmiLogout.addActionListener(new ActionListener(){ + jmiLogout.addActionListener(e -> { + //on passe � false toutes les valeurs + setIsAdmin(false); + setIsConnected(false); + setPlayer(null); - @Override - public void actionPerformed(ActionEvent e) - { - //on passe � false toutes les valeurs - setIsAdmin(false); - setIsConnected(false); - setPlayer(null); - - //on desactive le bouton Logout - Window.this.getJmiLogout().setEnabled(false); - - //Comme on se deconnecte on revient sur la page du d�but - getPanelCartes().getCl().show(getPanelCartes(), "Start"); - - // On desactive les boutons Admin - desactiveButtonsQuestions(); - - //on active le bouton login - Window.this.getJmiLogin().setEnabled(true); - - JOptionPane.showMessageDialog(null, "Logout succesfull !", "Information", JOptionPane.INFORMATION_MESSAGE); - - - } - - }); + //on desactive le bouton Logout + Window.this.getJmiLogout().setEnabled(false); + + //Comme on se deconnecte on revient sur la page du d�but + getPanelCartes().getCl().show(getPanelCartes(), "Start"); + + // On desactive les boutons Admin + desactiveButtonsQuestions(); + + //on active le bouton login + Window.this.getJmiLogin().setEnabled(true); + + JOptionPane.showMessageDialog(null, "Logout succesfull !", INFORMATION, JOptionPane.INFORMATION_MESSAGE); + + + + }); } return jmiLogout; } @@ -274,58 +270,51 @@ public class Window extends JFrame if(jmiLogin == null) { jmiLogin = new JMenuItem("Login"); - jmiLogin.addActionListener(new ActionListener(){ + jmiLogin.addActionListener(e -> { + PanelLogin panelLogin = new PanelLogin(); - @Override - public void actionPerformed(ActionEvent e) - { - PanelLogin panelLogin = new PanelLogin(); - - - int choixLog = panelLogin.isVerifyLoginAdmin(); - - if(choixLog == 0) // annulation - { - - } - else if(choixLog == 1) // connect� - { - isConnected = true; - - //on r�cupere le joueur connect� - Window.this.setPlayer(panelLogin.getPlayer()); - - //on active le logout - Window.this.getJmiLogout().setEnabled(true); - - // on desactive les boutons Admin - desactiveButtonsQuestions(); - - JOptionPane.showMessageDialog(null, "Logout succesfull as player !", "Information", JOptionPane.INFORMATION_MESSAGE); - - } - - else // connect� en admin - { - - //TODO on ne recupere pas l'admin pour le jeu ici - - // on active le bouton ajouter question et le logout - isAdmin = true; - isConnected = true; - Window.this.getJmiAddQuestion().setEnabled(true); - Window.this.getJmiLogout().setEnabled(true); - - // on active les boutons ajouter et supprimer du panelQuestion - PanelButtons panelButtonsQuestion = Window.this.getPanelCartes().getPanelQuestion().getPanelButtons(); - panelButtonsQuestion.getJbAjouter().setVisible(true); - panelButtonsQuestion.getjbSupprimer().setVisible(true); - - JOptionPane.showMessageDialog(null, "Login succesfull as Admin!", "Information", JOptionPane.INFORMATION_MESSAGE); - } - } - - }); + + int choixLog = panelLogin.isVerifyLoginAdmin(); + + if(choixLog == 0) // annulation + return; + + else if(choixLog == 1) // connect� + { + isConnected = true; + + //on r�cupere le joueur connect� + Window.this.setPlayer(panelLogin.getPlayer()); + + //on active le logout + Window.this.getJmiLogout().setEnabled(true); + + // on desactive les boutons Admin + desactiveButtonsQuestions(); + + JOptionPane.showMessageDialog(null, "Logout succesfull as player !", INFORMATION, JOptionPane.INFORMATION_MESSAGE); + + } + + else // connect� en admin + { + + //TODO on ne recupere pas l'admin pour le jeu ici + + // on active le bouton ajouter question et le logout + isAdmin = true; + isConnected = true; + Window.this.getJmiAddQuestion().setEnabled(true); + Window.this.getJmiLogout().setEnabled(true); + + // on active les boutons ajouter et supprimer du panelQuestion + PanelButtons panelButtonsQuestion = Window.this.getPanelCartes().getPanelQuestion().getPanelButtons(); + panelButtonsQuestion.getJbAjouter().setVisible(true); + panelButtonsQuestion.getjbSupprimer().setVisible(true); + + JOptionPane.showMessageDialog(null, "Login succesfull as Admin!", INFORMATION, JOptionPane.INFORMATION_MESSAGE); + } + }); } return jmiLogin; } @@ -345,7 +334,7 @@ public class Window extends JFrame @SuppressWarnings("deprecation") @Override public void actionPerformed(ActionEvent e) { - if(isActiver() == true){ + if(isActiver()){ setActiver(false); getSon().interrupt(); // on stoppe tout son } @@ -373,15 +362,7 @@ public class Window extends JFrame { jmiAddQuestion = new JMenuItem("Add Question"); jmiAddQuestion.setEnabled(false); - jmiAddQuestion.addActionListener(new ActionListener(){ - - public void actionPerformed(ActionEvent arg0) - { - Window.this.getPanelCartes().getCl().show(Window.this.getPanelCartes(),"AddQuestion"); - - } - - }); + jmiAddQuestion.addActionListener(arg0 -> Window.this.getPanelCartes().getCl().show(Window.this.getPanelCartes(),"AddQuestion")); } return jmiAddQuestion; } @@ -418,14 +399,11 @@ public class Window extends JFrame if(jmiFermer == null) { jmiFermer = new JMenuItem("Close"); - jmiFermer.addActionListener(new ActionListener(){ - public void actionPerformed(ActionEvent arg0) - { - int reponse = JOptionPane.showConfirmDialog(Window.this,"Voulez-vous quitter l'application","Confirmation",JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE); - if (reponse==JOptionPane.YES_OPTION) - System.exit(0); - } - }); + jmiFermer.addActionListener(arg0 -> { + int reponse = JOptionPane.showConfirmDialog(Window.this,"Voulez-vous quitter l'application","Confirmation",JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE); + if (reponse==JOptionPane.YES_OPTION) + System.exit(0); + }); } return jmiFermer; }