69 lines
1.9 KiB
Java
69 lines
1.9 KiB
Java
|
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");
|
||
|
}
|
||
|
}
|
||
|
}
|