Transférer les fichiers vers 'src/Test' #1
@ -1,239 +1,240 @@
|
|||||||
package Test;
|
package Test;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
|
|
||||||
public class MainMenu extends JFrame {
|
public class MainMenu extends JFrame {
|
||||||
private final static Dimension MINIMUM_SIZE = new Dimension(960, 600);
|
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 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 JPanel adminPanel = new JPanel(), profPanel = new JPanel(), studentPanel = new JPanel();
|
||||||
private final JMenuBar menuBar = new JMenuBar();
|
private final JMenuBar menuBar = new JMenuBar();
|
||||||
private Controller listener;
|
private Controller listener;
|
||||||
private AdminView av;
|
private AdminView av;
|
||||||
private ProfView pv;
|
private ProfView pv;
|
||||||
private StudentView sv;
|
private StudentView sv;
|
||||||
private JTable table;
|
private JTable table;
|
||||||
private int cardIndex = 0;
|
private int cardIndex = 0;
|
||||||
|
private String[] viewName = {"Administrateur", "Professeur", "Etudiant"}
|
||||||
private final JButton[] buttonTab = {
|
|
||||||
new JButton("Admin"),
|
private final JButton[] buttonTab = {
|
||||||
new JButton("Prof"),
|
new JButton(viewName[0]),
|
||||||
new JButton("Student")
|
new JButton(viewName[1]),
|
||||||
};
|
new JButton(viewName[2])
|
||||||
|
};
|
||||||
|
|
||||||
public MainMenu(Controller listener) {
|
|
||||||
super();
|
public MainMenu(Controller listener) {
|
||||||
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
|
super();
|
||||||
this.setExtendedState(MAXIMIZED_BOTH);
|
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
|
||||||
this.setMinimumSize(MINIMUM_SIZE);
|
this.setExtendedState(MAXIMIZED_BOTH);
|
||||||
init(listener);
|
this.setMinimumSize(MINIMUM_SIZE);
|
||||||
this.setVisible(true);
|
init(listener);
|
||||||
}
|
this.setVisible(true);
|
||||||
|
}
|
||||||
|
|
||||||
private void init(Controller listener) {
|
|
||||||
this.listener = listener;
|
private void init(Controller listener) {
|
||||||
|
this.listener = listener;
|
||||||
this.av = this.listener.getAdminView();
|
|
||||||
this.pv = this.listener.getProfView();
|
this.av = this.listener.getAdminView();
|
||||||
this.sv = this.listener.getStudentView();
|
this.pv = this.listener.getProfView();
|
||||||
|
this.sv = this.listener.getStudentView();
|
||||||
this.table = this.listener.initTable();
|
|
||||||
|
this.table = this.listener.initTable();
|
||||||
this.setLayout(cards);
|
|
||||||
|
this.setLayout(cards);
|
||||||
this.add(firstCard());
|
|
||||||
this.add(adminPanel);
|
this.add(firstCard());
|
||||||
this.add(profPanel);
|
this.add(adminPanel);
|
||||||
this.add(studentView());
|
this.add(profPanel);
|
||||||
|
this.add(studentView());
|
||||||
cards.first(this.getContentPane());
|
|
||||||
}
|
cards.first(this.getContentPane());
|
||||||
|
}
|
||||||
|
|
||||||
private void createJMenuBar() {
|
|
||||||
JMenu menu = new JMenu("Menu"), file = new JMenu("File"), edit = new JMenu("Edit"), view = new JMenu("View");
|
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));
|
JMenuItem adminMenuItem = new JMenuItem("Vu "+viewName[0]);
|
||||||
|
adminMenuItem.addActionListener((event) -> changeView(1));
|
||||||
JMenuItem profMenuItem = new JMenuItem("Professor View");
|
|
||||||
profMenuItem.addActionListener((event) -> changeView(2));
|
JMenuItem profMenuItem = new JMenuItem("Vu "+viewName[0]);
|
||||||
|
profMenuItem.addActionListener((event) -> changeView(2));
|
||||||
JMenuItem studentMenuItem = new JMenuItem("Student View");
|
|
||||||
studentMenuItem.addActionListener((event) -> changeView(3));
|
JMenuItem studentMenuItem = new JMenuItem("Vu "+viewName[0]);
|
||||||
|
studentMenuItem.addActionListener((event) -> changeView(3));
|
||||||
JMenuItem quitMenuItem = new JMenuItem("Quit");
|
|
||||||
quitMenuItem.addActionListener((event) -> System.exit(0));
|
JMenuItem quitMenuItem = new JMenuItem("Quitter");
|
||||||
|
quitMenuItem.addActionListener((event) -> System.exit(0));
|
||||||
menu.add(adminMenuItem);
|
|
||||||
menu.add(profMenuItem);
|
menu.add(adminMenuItem);
|
||||||
menu.add(studentMenuItem);
|
menu.add(profMenuItem);
|
||||||
menu.add(quitMenuItem);
|
menu.add(studentMenuItem);
|
||||||
|
menu.add(quitMenuItem);
|
||||||
file.add(new JMenuItem("Ca c'est juste du style"));
|
|
||||||
edit.add(new JMenuItem("Ca aussi c'est du style"));
|
file.add(new JMenuItem("Ca c'est juste du style"));
|
||||||
view.add(new JMenuItem("Encore du style"));
|
edit.add(new JMenuItem("Ca aussi c'est du style"));
|
||||||
|
view.add(new JMenuItem("Encore du style"));
|
||||||
menuBar.add(menu);
|
|
||||||
menuBar.add(file);
|
menuBar.add(menu);
|
||||||
menuBar.add(edit);
|
menuBar.add(file);
|
||||||
menuBar.add(view);
|
menuBar.add(edit);
|
||||||
|
menuBar.add(view);
|
||||||
this.setJMenuBar(menuBar);
|
|
||||||
}
|
this.setJMenuBar(menuBar);
|
||||||
|
}
|
||||||
|
|
||||||
private JPanel cardWithTable(JPanel sidePanel) {
|
|
||||||
JPanel panel = new JPanel();
|
private JPanel cardWithTable(JPanel sidePanel) {
|
||||||
JScrollPane scrollPane = new JScrollPane();
|
JPanel panel = new JPanel();
|
||||||
|
JScrollPane scrollPane = new JScrollPane();
|
||||||
panel.setLayout(new GridLayout(1, 2));
|
|
||||||
|
panel.setLayout(new GridLayout(1, 2));
|
||||||
panel.add(sidePanel);
|
|
||||||
panel.add(this.table);
|
panel.add(sidePanel);
|
||||||
panel.add(scrollPane);
|
panel.add(this.table);
|
||||||
scrollPane.setViewportView(this.table);
|
panel.add(scrollPane);
|
||||||
|
scrollPane.setViewportView(this.table);
|
||||||
return panel;
|
|
||||||
}
|
return panel;
|
||||||
|
}
|
||||||
|
|
||||||
private void changeView(int index) {
|
|
||||||
table = this.listener.initTable();
|
private void changeView(int index) {
|
||||||
|
table = this.listener.initTable();
|
||||||
if (index == 1) {
|
|
||||||
cardIndex = index;
|
if (index == 1) {
|
||||||
this.setTitle("Administrator");
|
cardIndex = index;
|
||||||
adminPanel.setLayout(adminCards);
|
this.setTitle(viewName[0]);
|
||||||
adminPanel.add(cardWithTable(adminView()));
|
adminPanel.setLayout(adminCards);
|
||||||
adminCards.next(adminPanel);
|
adminPanel.add(cardWithTable(adminView()));
|
||||||
menuBar.setBackground(Color.RED);
|
adminCards.next(adminPanel);
|
||||||
|
menuBar.setBackground(Color.RED);
|
||||||
} else if (index == 2) {
|
|
||||||
cardIndex = index;
|
} else if (index == 2) {
|
||||||
this.setTitle("Professor");
|
cardIndex = index;
|
||||||
profPanel.setLayout(profCards);
|
this.setTitle(viewName[1]);
|
||||||
profPanel.add(cardWithTable(profView()));
|
profPanel.setLayout(profCards);
|
||||||
profCards.next(profPanel);
|
profPanel.add(cardWithTable(profView()));
|
||||||
menuBar.setBackground(Color.MAGENTA);
|
profCards.next(profPanel);
|
||||||
|
menuBar.setBackground(Color.MAGENTA);
|
||||||
} else if (index == 3){
|
|
||||||
cardIndex = index;
|
} else if (index == 3){
|
||||||
this.setTitle("Student");
|
cardIndex = index;
|
||||||
studentPanel.setLayout(studentCards);
|
this.setTitle(viewName[2]);
|
||||||
studentPanel.add(cardWithTable(studentView()));
|
studentPanel.setLayout(studentCards);
|
||||||
studentCards.next(studentPanel);
|
studentPanel.add(cardWithTable(studentView()));
|
||||||
menuBar.setBackground(Color.BLUE);
|
studentCards.next(studentPanel);
|
||||||
}
|
menuBar.setBackground(Color.BLUE);
|
||||||
travelThroughCards(index);
|
}
|
||||||
}
|
travelThroughCards(index);
|
||||||
|
}
|
||||||
|
|
||||||
public void updateTable(JTable table) {
|
|
||||||
if (cardIndex == 1) {
|
public void updateTable(JTable table) {
|
||||||
this.table = table;
|
if (cardIndex == 1) {
|
||||||
adminPanel.add(cardWithTable(adminView()));
|
this.table = table;
|
||||||
adminCards.next(adminPanel);
|
adminPanel.add(cardWithTable(adminView()));
|
||||||
} else if (cardIndex == 2) {
|
adminCards.next(adminPanel);
|
||||||
this.table = table;
|
} else if (cardIndex == 2) {
|
||||||
profPanel.add(cardWithTable(profView()));
|
this.table = table;
|
||||||
profCards.next(profPanel);
|
profPanel.add(cardWithTable(profView()));
|
||||||
} else {
|
profCards.next(profPanel);
|
||||||
this.table = table;
|
} else {
|
||||||
studentPanel.add(cardWithTable(profView()));
|
this.table = table;
|
||||||
studentCards.next(studentPanel);
|
studentPanel.add(cardWithTable(profView()));
|
||||||
}
|
studentCards.next(studentPanel);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private JPanel firstCard() {
|
|
||||||
JPanel mainPanel = new JPanel(), centerPanel = new JPanel();
|
private JPanel firstCard() {
|
||||||
Dimension buttonDimension = new Dimension(300, 50);
|
JPanel mainPanel = new JPanel(), centerPanel = new JPanel();
|
||||||
|
Dimension buttonDimension = new Dimension(300, 50);
|
||||||
mainPanel.setLayout(new BorderLayout());
|
|
||||||
centerPanel.setLayout(new GridBagLayout());
|
mainPanel.setLayout(new BorderLayout());
|
||||||
|
centerPanel.setLayout(new GridBagLayout());
|
||||||
Insets insets = new Insets(10, 10, 10, 10);
|
|
||||||
GridBagConstraints gbc = new GridBagConstraints();
|
Insets insets = new Insets(10, 10, 10, 10);
|
||||||
gbc.insets = insets;
|
GridBagConstraints gbc = new GridBagConstraints();
|
||||||
gbc.gridwidth = 1;
|
gbc.insets = insets;
|
||||||
gbc.gridx = 0;
|
gbc.gridwidth = 1;
|
||||||
|
gbc.gridx = 0;
|
||||||
for (int i = 0; i < buttonTab.length; i++) {
|
|
||||||
gbc.gridy = i;
|
for (int i = 0; i < buttonTab.length; i++) {
|
||||||
buttonTab[i].setPreferredSize(buttonDimension);
|
gbc.gridy = i;
|
||||||
buttonTab[i].addActionListener(this::action);
|
buttonTab[i].setPreferredSize(buttonDimension);
|
||||||
centerPanel.add(buttonTab[i], gbc);
|
buttonTab[i].addActionListener(this::action);
|
||||||
}
|
centerPanel.add(buttonTab[i], gbc);
|
||||||
|
}
|
||||||
mainPanel.add(centerPanel, BorderLayout.CENTER);
|
|
||||||
|
mainPanel.add(centerPanel, BorderLayout.CENTER);
|
||||||
return mainPanel;
|
|
||||||
}
|
return mainPanel;
|
||||||
|
}
|
||||||
|
|
||||||
private JPanel adminView() {
|
|
||||||
JPanel mainPanel = new JPanel();
|
private JPanel adminView() {
|
||||||
mainPanel.setLayout(new BorderLayout());
|
JPanel mainPanel = new JPanel();
|
||||||
mainPanel.add(this.av, BorderLayout.CENTER);
|
mainPanel.setLayout(new BorderLayout());
|
||||||
return mainPanel;
|
mainPanel.add(this.av, BorderLayout.CENTER);
|
||||||
}
|
return mainPanel;
|
||||||
|
}
|
||||||
|
|
||||||
private JPanel profView() {
|
|
||||||
JPanel mainPanel = new JPanel();
|
private JPanel profView() {
|
||||||
mainPanel.setLayout(new BorderLayout());
|
JPanel mainPanel = new JPanel();
|
||||||
mainPanel.add(this.pv, BorderLayout.CENTER);
|
mainPanel.setLayout(new BorderLayout());
|
||||||
return mainPanel;
|
mainPanel.add(this.pv, BorderLayout.CENTER);
|
||||||
}
|
return mainPanel;
|
||||||
|
}
|
||||||
|
|
||||||
private JPanel studentView() {
|
|
||||||
JPanel mainPanel = new JPanel();
|
private JPanel studentView() {
|
||||||
mainPanel.setLayout(new BorderLayout());
|
JPanel mainPanel = new JPanel();
|
||||||
mainPanel.add(this.sv, BorderLayout.CENTER);
|
mainPanel.setLayout(new BorderLayout());
|
||||||
return mainPanel;
|
mainPanel.add(this.sv, BorderLayout.CENTER);
|
||||||
}
|
return mainPanel;
|
||||||
|
}
|
||||||
|
|
||||||
private void action(ActionEvent e) {
|
|
||||||
JButton origin = (JButton) e.getSource();
|
private void action(ActionEvent e) {
|
||||||
createJMenuBar();
|
JButton origin = (JButton) e.getSource();
|
||||||
|
createJMenuBar();
|
||||||
if (origin.getText().equals("Admin")) {
|
|
||||||
this.setTitle("Administrator");
|
if (origin.getText().equals("Admin")) {
|
||||||
menuBar.setBackground(Color.RED);
|
this.setTitle(viewName[0]);
|
||||||
adminPanel.setLayout(adminCards);
|
menuBar.setBackground(Color.RED);
|
||||||
adminPanel.add(cardWithTable(adminView()));
|
adminPanel.setLayout(adminCards);
|
||||||
cardIndex = 1;
|
adminPanel.add(cardWithTable(adminView()));
|
||||||
|
cardIndex = 1;
|
||||||
} else if (origin.getText().equals("Prof")) {
|
|
||||||
this.setTitle("Professor");
|
} else if (origin.getText().equals("Prof")) {
|
||||||
menuBar.setBackground(Color.MAGENTA);
|
this.setTitle(viewName[1]);
|
||||||
profPanel.setLayout(profCards);
|
menuBar.setBackground(Color.MAGENTA);
|
||||||
profPanel.add(cardWithTable(profView()));
|
profPanel.setLayout(profCards);
|
||||||
cardIndex = 2;
|
profPanel.add(cardWithTable(profView()));
|
||||||
|
cardIndex = 2;
|
||||||
} else {
|
|
||||||
this.setTitle("Student");
|
} else {
|
||||||
menuBar.setBackground(Color.BLUE);
|
this.setTitle(viewName[2]);
|
||||||
studentPanel.setLayout(studentCards);
|
menuBar.setBackground(Color.BLUE);
|
||||||
studentPanel.add(cardWithTable(studentView()));
|
studentPanel.setLayout(studentCards);
|
||||||
cardIndex = 3;
|
studentPanel.add(cardWithTable(studentView()));
|
||||||
}
|
cardIndex = 3;
|
||||||
|
}
|
||||||
travelThroughCards(cardIndex);
|
|
||||||
}
|
travelThroughCards(cardIndex);
|
||||||
|
}
|
||||||
|
|
||||||
private void travelThroughCards(int index) {
|
|
||||||
cards.first(this.getContentPane());
|
private void travelThroughCards(int index) {
|
||||||
|
cards.first(this.getContentPane());
|
||||||
for (int i = 0; i < index; i++) {
|
|
||||||
cards.next(this.getContentPane());
|
for (int i = 0; i < index; i++) {
|
||||||
}
|
cards.next(this.getContentPane());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user