Files
FIProjetIHM2022/src/Test/MainMenu.java

124 lines
3.4 KiB
Java
Raw Normal View History

package Test;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
public class MainMenu extends JFrame {
private final static Dimension MINIMUM_SIZE = new Dimension(960, 540);
2022-12-01 18:59:34 +01:00
private CardLayout cards;
private AdminView av;
2022-12-01 18:59:34 +01:00
private StudentView sv;
private ProfView pv;
2022-12-01 18:59:34 +01:00
private BLayout settings;
2022-12-01 18:59:34 +01:00
private final Controller listener;
2022-12-01 18:59:34 +01:00
private JButton[] buttonTab;
2022-12-01 18:59:34 +01:00
public MainMenu(Controller listener) {
super();
2022-12-01 18:59:34 +01:00
this.av = listener.getAdminView();
this.pv = listener.getProfView();
this.sv = listener.getStudentView();
this.cards = new CardLayout();
this.listener = listener;
this.buttonTab = new JButton[] {
new JButton("Admin"),
new JButton("Prof"),
new JButton("Student")
};
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setExtendedState(MAXIMIZED_BOTH);
this.setMinimumSize(MINIMUM_SIZE);
2022-12-01 18:59:34 +01:00
this.init();
this.setVisible(true);
}
private void init() {
2022-12-01 18:59:34 +01:00
this.setLayout(this.cards);
this.add(first());
2022-12-01 18:59:34 +01:00
this.add(adminView());
this.add(profView());
this.add(studentView());
2022-12-01 18:59:34 +01:00
this.cards.first(this.getContentPane());
}
private JPanel first() {
2022-12-01 18:59:34 +01:00
JPanel mainPanel = new JPanel();
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 JPanel adminView() {
2022-12-01 18:59:34 +01:00
JPanel mainPanel = new JPanel(new GridBagLayout());
mainPanel.add(this.av, this.settings);
return mainPanel;
}
private JPanel profView() {
2022-12-01 18:59:34 +01:00
JPanel mainPanel = new JPanel(new GridBagLayout());
mainPanel.add(this.pv, this.settings);
return mainPanel;
}
2022-12-01 18:59:34 +01:00
private JPanel studentView() {
JPanel mainPanel = new JPanel(new GridBagLayout());
mainPanel.add(this.sv, this.settings);
return mainPanel;
}
private void action(ActionEvent e) {
JButton origin = (JButton) e.getSource();
System.out.println(origin.getText());
if (origin.getText() == "Admin") {
cards.next(this.getContentPane());
} else if (origin.getText() == "Prof") {
cards.next(this.getContentPane());
cards.next(this.getContentPane());
2022-12-01 18:59:34 +01:00
} else if (origin.getText() == "Student") {
cards.next(this.getContentPane());
cards.next(this.getContentPane());
cards.next(this.getContentPane());
}
2022-12-01 18:59:34 +01:00
else {
JOptionPane.showMessageDialog(null, "En travaux");
}
}
}