From 8b68a2a1632bf691b8c5cb2daf5016ffe78a1778 Mon Sep 17 00:00:00 2001 From: besson Date: Thu, 1 Dec 2022 22:34:29 +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 | 111 +++++++++++++++++++++++++++-------------- 1 file changed, 73 insertions(+), 38 deletions(-) diff --git a/src/Test/MainMenu.java b/src/Test/MainMenu.java index b939830..90688bf 100644 --- a/src/Test/MainMenu.java +++ b/src/Test/MainMenu.java @@ -5,51 +5,49 @@ import java.awt.*; import java.awt.event.ActionEvent; public class MainMenu extends JFrame { - private final static Dimension MINIMUM_SIZE = new Dimension(960, 540); - private CardLayout cards = new CardLayout(), adminCards = new CardLayout(), profCards = new CardLayout(); - private JPanel adminPanel = new JPanel(), profPanel = new JPanel(); - private JMenuBar menuBar = new JMenuBar(); + 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 Controller listener; private AdminView av; private ProfView pv; + private StudentView sv; private JTable table; private int cardIndex = 0; - private JButton[] buttonTab = { + private final JButton[] buttonTab = { new JButton("Admin"), new JButton("Prof"), new JButton("Student") }; - public MainMenu() { + public MainMenu(Controller listener) { super(); this.setDefaultCloseOperation(EXIT_ON_CLOSE); this.setExtendedState(MAXIMIZED_BOTH); this.setMinimumSize(MINIMUM_SIZE); - init(); + init(listener); this.setVisible(true); } - private void init() { - BDatabase db = new BDatabase(); - Controller listener = new Controller(db, this); + private void init(Controller listener) { + this.listener = listener; - this.av = new AdminView(listener.getEtudiants(), listener.getGroupes(), listener); - this.pv = new ProfView(listener.getEtudiants(), listener.getGroupes(), listener); + this.av = this.listener.getAdminView(); + this.pv = this.listener.getProfView(); + this.sv = this.listener.getStudentView(); - listener.setAv(av); - listener.setPv(pv); - - this.table = listener.initTable(); - - createJMenuBar(); + this.table = this.listener.initTable(); this.setLayout(cards); - this.add(first()); + this.add(firstCard()); this.add(adminPanel); this.add(profPanel); + this.add(studentView()); cards.first(this.getContentPane()); } @@ -57,7 +55,7 @@ public class MainMenu extends JFrame { private void createJMenuBar() { JMenu menu = new JMenu("Menu"), file = new JMenu("File"), edit = new JMenu("Edit"), view = new JMenu("View"); - + JMenuItem adminMenuItem = new JMenuItem("Admin View"); adminMenuItem.addActionListener((event) -> changeView(1)); @@ -83,6 +81,7 @@ public class MainMenu extends JFrame { menuBar.add(file); menuBar.add(edit); menuBar.add(view); + this.setJMenuBar(menuBar); } @@ -103,24 +102,33 @@ public class MainMenu extends JFrame { private void changeView(int index) { + table = this.listener.initTable(); + if (index == 1) { cardIndex = index; - cards.first(this.getContentPane()); - cards.next(this.getContentPane()); + this.setTitle("Administrator"); + adminPanel.setLayout(adminCards); adminPanel.add(cardWithTable(adminView())); adminCards.next(adminPanel); + menuBar.setBackground(Color.RED); } else if (index == 2) { cardIndex = index; - cards.first(this.getContentPane()); - cards.next(this.getContentPane()); - cards.next(this.getContentPane()); + this.setTitle("Professor"); + profPanel.setLayout(profCards); profPanel.add(cardWithTable(profView())); profCards.next(profPanel); + menuBar.setBackground(Color.MAGENTA); } else if (index == 3){ - JOptionPane.showMessageDialog(null, "En travaux"); + cardIndex = index; + this.setTitle("Student"); + studentPanel.setLayout(studentCards); + studentPanel.add(cardWithTable(studentView())); + studentCards.next(studentPanel); + menuBar.setBackground(Color.BLUE); } + travelThroughCards(index); } @@ -134,12 +142,14 @@ public class MainMenu extends JFrame { profPanel.add(cardWithTable(profView())); profCards.next(profPanel); } else { - + this.table = table; + studentPanel.add(cardWithTable(profView())); + studentCards.next(studentPanel); } } - private JPanel first() { + private JPanel firstCard() { JPanel mainPanel = new JPanel(), centerPanel = new JPanel(); Dimension buttonDimension = new Dimension(300, 50); @@ -167,38 +177,63 @@ public class MainMenu extends JFrame { private JPanel adminView() { JPanel mainPanel = new JPanel(); - mainPanel.add(av); + mainPanel.setLayout(new BorderLayout()); + mainPanel.add(this.av, BorderLayout.CENTER); return mainPanel; } private JPanel profView() { JPanel mainPanel = new JPanel(); - mainPanel.add(pv); + mainPanel.setLayout(new BorderLayout()); + mainPanel.add(this.pv, BorderLayout.CENTER); + return mainPanel; + } + + + private JPanel studentView() { + JPanel mainPanel = new JPanel(); + mainPanel.setLayout(new BorderLayout()); + mainPanel.add(this.sv, BorderLayout.CENTER); return mainPanel; } private void action(ActionEvent e) { JButton origin = (JButton) e.getSource(); - System.out.println(origin.getText()); + createJMenuBar(); - if (origin.getText() == "Admin") { + if (origin.getText().equals("Admin")) { + this.setTitle("Administrator"); + menuBar.setBackground(Color.RED); adminPanel.setLayout(adminCards); adminPanel.add(cardWithTable(adminView())); - cards.next(this.getContentPane()); cardIndex = 1; - } else if (origin.getText() == "Prof") { + } else if (origin.getText().equals("Prof")) { + this.setTitle("Professor"); + menuBar.setBackground(Color.MAGENTA); profPanel.setLayout(profCards); profPanel.add(cardWithTable(profView())); - cards.next(this.getContentPane()); - cards.next(this.getContentPane()); cardIndex = 2; } else { - JOptionPane.showMessageDialog(null, "En travaux"); - //cardIndex = 3; + this.setTitle("Student"); + menuBar.setBackground(Color.BLUE); + studentPanel.setLayout(studentCards); + studentPanel.add(cardWithTable(studentView())); + cardIndex = 3; + } + + travelThroughCards(cardIndex); + } + + + private void travelThroughCards(int index) { + cards.first(this.getContentPane()); + + for (int i = 0; i < index; i++) { + cards.next(this.getContentPane()); } } }