From 1430f84f2163cd58968bb69dcec4429a2380c7b7 Mon Sep 17 00:00:00 2001 From: besson Date: Thu, 1 Dec 2022 11:18:45 +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/Controller.java | 26 +++++++++++---- src/Test/MainMenu.java | 68 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+), 6 deletions(-) create mode 100644 src/Test/MainMenu.java diff --git a/src/Test/Controller.java b/src/Test/Controller.java index c4fe9d7..ba86ffe 100644 --- a/src/Test/Controller.java +++ b/src/Test/Controller.java @@ -18,8 +18,8 @@ import java.util.Objects; public class Controller implements ActionListener, ListSelectionListener { private final BDatabase db; - private final ProfView pv; - private final AdminView av; + private ProfView pv = null; + private AdminView av = null; private BFrame currentModal; private ArrayList e; @@ -36,10 +36,10 @@ public class Controller implements ActionListener, ListSelectionListener { this.g = this.db.getGroupeList(); // Les 3 fenetres s'ouvriront en meme temps (Pour le contexte du projet) - this.pv = new ProfView(this.e, this.g, this); - System.out.println("[+] Demarrage de la vue professeur -> " + this.pv); - this.av = new AdminView(this.e, this.g, this); - System.out.println("[+] Demarrage de la vue Administrateur -> " + this.av); + //this.pv = new ProfView(this.e, this.g, this); + //System.out.println("[+] Demarrage de la vue professeur -> " + this.pv); + //this.av = new AdminView(this.e, this.g, this); + //System.out.println("[+] Demarrage de la vue Administrateur -> " + this.av); } /** @@ -438,4 +438,18 @@ public class Controller implements ActionListener, ListSelectionListener { } } } + + + public void createProfView () { + if (this.pv == null) { + this.pv = new ProfView(this.e, this.g, this); + } + } + + + public void createAdminView () { + if (this.av == null) { + this.av = new AdminView(this.e, this.g, this); + } + } } \ No newline at end of file diff --git a/src/Test/MainMenu.java b/src/Test/MainMenu.java new file mode 100644 index 0000000..948c378 --- /dev/null +++ b/src/Test/MainMenu.java @@ -0,0 +1,68 @@ +package Test; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; + +public class MainMenu extends JFrame { + private CardLayout cards = new CardLayout(); + private JButton[] buttonTab = { + new JButton("Admin"), + new JButton("Prof"), + new JButton("Student") + }; + + + public MainMenu() { + super(); + this.setDefaultCloseOperation(EXIT_ON_CLOSE); + this.setExtendedState(MAXIMIZED_BOTH); + //this.setUndecorated(true); + this.setLayout(cards); + this.add(first()); + cards.first(this.getContentPane()); + this.setVisible(true); + } + + + private JPanel first() { + JPanel mainPanel = new JPanel(), centerPanel = new JPanel(); + Dimension buttonDimension = new Dimension(300, 50); + + mainPanel.setLayout(new BorderLayout()); + centerPanel.setLayout(new GridBagLayout()); + + Insets insets = new Insets(10, 10, 10, 10); + GridBagConstraints gbc = new GridBagConstraints(); + gbc.insets = insets; + gbc.gridwidth = 1; + gbc.gridx = 0; + + for (int i = 0; i < buttonTab.length; i++) { + gbc.gridy = i; + buttonTab[i].setPreferredSize(buttonDimension); + buttonTab[i].addActionListener(this::action); + centerPanel.add(buttonTab[i], gbc); + } + + mainPanel.add(centerPanel, BorderLayout.CENTER); + + return mainPanel; + } + + + private void action(ActionEvent e) { + JButton origin = (JButton) e.getSource(); + + BDatabase db = new BDatabase(); + Controller listener = new Controller(db); + + if (origin.getText() == "Admin") { + listener.createAdminView(); + } else if (origin.getText() == "Prof") { + listener.createProfView(); + } else { + JOptionPane.showMessageDialog(null, "En travaux"); + } + } +}