From 6d9bf03e13fdcf547bb9d2518ae0c38196d3e3c5 Mon Sep 17 00:00:00 2001 From: besson Date: Fri, 2 Dec 2022 11:33:37 +0100 Subject: [PATCH] =?UTF-8?q?Transf=C3=A9rer=20les=20fichiers=20vers=20'src/?= =?UTF-8?q?Test'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Test/MainMenu.java | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/src/Test/MainMenu.java b/src/Test/MainMenu.java index 58112d2..f2e6490 100644 --- a/src/Test/MainMenu.java +++ b/src/Test/MainMenu.java @@ -8,7 +8,7 @@ public class MainMenu extends JFrame { private final static Dimension MINIMUM_SIZE = new Dimension(960, 600); private final CardLayout cards = new CardLayout(), adminCards = new CardLayout(), profCards = new CardLayout(), studentCards = new CardLayout(); private final JPanel adminPanel = new JPanel(), profPanel = new JPanel(), studentPanel = new JPanel(); - private final JMenuBar menuBar = new JMenuBar(); + private JMenuBar menuBar; private Controller listener; private AdminView av; private ProfView pv; @@ -16,7 +16,6 @@ public class MainMenu extends JFrame { private JTable table; private int cardIndex = 0; private String[] viewName = {"Administrateur", "Professeur", "Etudiant"}; - private final JButton[] buttonTab = { new JButton(viewName[0]), new JButton(viewName[1]), @@ -48,7 +47,7 @@ public class MainMenu extends JFrame { this.add(firstCard()); this.add(adminPanel); this.add(profPanel); - this.add(studentView()); + this.add(studentPanel); cards.first(this.getContentPane()); } @@ -66,12 +65,16 @@ public class MainMenu extends JFrame { JMenuItem studentMenuItem = new JMenuItem("Vu "+viewName[2]); studentMenuItem.addActionListener((event) -> changeView(3)); + JMenuItem mainMenuItem = new JMenuItem("Retourner au menu principal"); + mainMenuItem.addActionListener(this::backtoMainMenu); + JMenuItem quitMenuItem = new JMenuItem("Quitter"); quitMenuItem.addActionListener((event) -> System.exit(0)); menu.add(adminMenuItem); menu.add(profMenuItem); menu.add(studentMenuItem); + menu.add(mainMenuItem); menu.add(quitMenuItem); file.add(new JMenuItem("Ca c'est juste du style")); @@ -87,6 +90,12 @@ public class MainMenu extends JFrame { } + private void backtoMainMenu(ActionEvent e) { + this.setJMenuBar(null); + cards.first(this.getContentPane()); + } + + private JPanel cardWithTable(JPanel sidePanel) { JPanel panel = new JPanel(); JScrollPane scrollPane = new JScrollPane(); @@ -202,13 +211,20 @@ public class MainMenu extends JFrame { private void action(ActionEvent e) { JButton origin = (JButton) e.getSource(); - createJMenuBar(); + + if (menuBar == null) { + menuBar = new JMenuBar(); + createJMenuBar(); + } else { + this.setJMenuBar(menuBar); + } if (origin.getText().equals(viewName[0])) { this.setTitle(viewName[0]); menuBar.setBackground(Color.RED); adminPanel.setLayout(adminCards); adminPanel.add(cardWithTable(adminView())); + adminCards.next(adminPanel); cardIndex = 1; } else if (origin.getText().equals(viewName[1])) { @@ -216,6 +232,7 @@ public class MainMenu extends JFrame { menuBar.setBackground(Color.MAGENTA); profPanel.setLayout(profCards); profPanel.add(cardWithTable(profView())); + profCards.next(profPanel); cardIndex = 2; } else { @@ -223,6 +240,7 @@ public class MainMenu extends JFrame { menuBar.setBackground(Color.BLUE); studentPanel.setLayout(studentCards); studentPanel.add(cardWithTable(studentView())); + studentCards.next(studentPanel); cardIndex = 3; }