Modification des menus
This commit is contained in:
parent
c75731439b
commit
a1ae3bdc43
@ -4,11 +4,13 @@ import java.awt.event.ActionListener;
|
|||||||
/**
|
/**
|
||||||
* Listener for button clicks in the menu.
|
* Listener for button clicks in the menu.
|
||||||
* It performs different actions based on the button clicked.
|
* It performs different actions based on the button clicked.
|
||||||
|
* @version 1.0
|
||||||
|
* @author Moncef STITI
|
||||||
|
* @author Marco ORFAO
|
||||||
*/
|
*/
|
||||||
class HomeButtonClickListener implements ActionListener {
|
class HomeButtonClickListener implements ActionListener {
|
||||||
private Window window;
|
private Window window;
|
||||||
private DialogManager rulesDialogManager;
|
private DialogManager rulesDialogManager;
|
||||||
private DialogManager howToPlayDialogManager;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a ButtonClickListener with the specified window.
|
* Constructs a ButtonClickListener with the specified window.
|
||||||
@ -17,7 +19,6 @@ class HomeButtonClickListener implements ActionListener {
|
|||||||
public HomeButtonClickListener(Window window) {
|
public HomeButtonClickListener(Window window) {
|
||||||
this.window = window;
|
this.window = window;
|
||||||
this.rulesDialogManager = new RulesDialogManager();
|
this.rulesDialogManager = new RulesDialogManager();
|
||||||
this.howToPlayDialogManager = new HowToPlayDialogManager();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -29,14 +30,14 @@ class HomeButtonClickListener implements ActionListener {
|
|||||||
String buttonText = ((Button) e.getSource()).getText();
|
String buttonText = ((Button) e.getSource()).getText();
|
||||||
switch (buttonText) {
|
switch (buttonText) {
|
||||||
case "Jouer":
|
case "Jouer":
|
||||||
PlayMenuView playMenu = new PlayMenuView(window);
|
System.out.println("Bouton jouer cliquer"); // lancer jeu
|
||||||
window.changeMenu(playMenu);
|
break;
|
||||||
|
case "Générer une grille":
|
||||||
|
Window.removeAllComponents(this.window); // Supprimer tout ce qu'il y a sur la fenêtre
|
||||||
|
new GridMakeUserInterfaceView(this.window); // Lancer le créateur de grille
|
||||||
break;
|
break;
|
||||||
case "Règles":
|
case "Règles":
|
||||||
rulesDialogManager.showDialog();
|
rulesDialogManager.showDialog(); // Afficher les règles
|
||||||
break;
|
|
||||||
case "Comment jouer ?":
|
|
||||||
howToPlayDialogManager.showDialog();
|
|
||||||
break;
|
break;
|
||||||
case "Quitter":
|
case "Quitter":
|
||||||
System.exit(0); // Quitter le programme
|
System.exit(0); // Quitter le programme
|
||||||
|
@ -12,7 +12,7 @@ public class HomeView extends JPanel {
|
|||||||
private final Font TITLE_FONT = new Font("Copperplate", Font.BOLD, 75);
|
private final Font TITLE_FONT = new Font("Copperplate", Font.BOLD, 75);
|
||||||
private final Font SUBTITLE_FONT = new Font("Copperplate", Font.PLAIN, 24);
|
private final Font SUBTITLE_FONT = new Font("Copperplate", Font.PLAIN, 24);
|
||||||
private final Font BUTTON_FONT = new Font("Copperplate", Font.BOLD, 24);
|
private final Font BUTTON_FONT = new Font("Copperplate", Font.BOLD, 24);
|
||||||
private final String[] BUTTON_TEXTS = {"Jouer", "Règles", "Comment jouer ?", "Quitter"};
|
private final String[] BUTTON_TEXTS = {"Jouer", "Générer une grille", "Règles", "Quitter"};
|
||||||
private final Title[] labels = {
|
private final Title[] labels = {
|
||||||
new Title("Sudoku Solver", TITLE_FONT, TITLE_TEXT_COLOR),
|
new Title("Sudoku Solver", TITLE_FONT, TITLE_TEXT_COLOR),
|
||||||
new Title("Par Moncef & Marco", SUBTITLE_FONT, TITLE_TEXT_COLOR)
|
new Title("Par Moncef & Marco", SUBTITLE_FONT, TITLE_TEXT_COLOR)
|
||||||
|
@ -1,9 +0,0 @@
|
|||||||
import javax.swing.JOptionPane;
|
|
||||||
|
|
||||||
public class HowToPlayDialogManager implements DialogManager {
|
|
||||||
@Override
|
|
||||||
public void showDialog() {
|
|
||||||
HowToPlaySudoku howToPlay = new HowToPlaySudoku();
|
|
||||||
JOptionPane.showMessageDialog(null, howToPlay, "Comment jouer ?", JOptionPane.PLAIN_MESSAGE);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,34 +0,0 @@
|
|||||||
import javax.swing.*;
|
|
||||||
import java.awt.*;
|
|
||||||
|
|
||||||
public class HowToPlaySudoku extends JPanel {
|
|
||||||
|
|
||||||
public HowToPlaySudoku() {
|
|
||||||
BorderLayout gestionnaireBorderLayout = new BorderLayout();
|
|
||||||
this.setLayout(gestionnaireBorderLayout);
|
|
||||||
this.setBackground(new Color(54, 91, 109)); // Couleur d'arrière-plan du menu principal
|
|
||||||
|
|
||||||
JLabel titleLabel = new JLabel("Comment jouer ?");
|
|
||||||
titleLabel.setFont(new Font("Copperplate", Font.BOLD, 40)); // Police du titre
|
|
||||||
titleLabel.setForeground(Color.WHITE); // Couleur du titre
|
|
||||||
|
|
||||||
JTextArea rulesTextArea = new JTextArea();
|
|
||||||
rulesTextArea.setText("1. EXPLIQUER CE QU'IL FAUT FAIRE\n\n" +
|
|
||||||
"2. EXPLIQUER CE QU'IL FAUT FAIRE \n\n" +
|
|
||||||
"3. EXPLIQUER CE QU'IL FAUT FAIRE \n\n" +
|
|
||||||
"4. EXPLIQUER CE QU'IL FAUT FAIRE");
|
|
||||||
rulesTextArea.setEditable(false);
|
|
||||||
rulesTextArea.setLineWrap(true);
|
|
||||||
rulesTextArea.setWrapStyleWord(true);
|
|
||||||
rulesTextArea.setFont(new Font("Arial", Font.PLAIN, 20)); // Police du texte
|
|
||||||
rulesTextArea.setForeground(Color.WHITE); // Couleur du texte
|
|
||||||
rulesTextArea.setBackground(new Color(54, 91, 109)); // Couleur d'arrière-plan du JLabel
|
|
||||||
|
|
||||||
JScrollPane scrollPane = new JScrollPane(rulesTextArea);
|
|
||||||
|
|
||||||
this.add(titleLabel, BorderLayout.NORTH);
|
|
||||||
this.add(scrollPane, BorderLayout.CENTER);
|
|
||||||
|
|
||||||
this.setPreferredSize(new Dimension(400, 500)); // Taille de la fenêtre
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,31 +0,0 @@
|
|||||||
import java.awt.event.ActionEvent;
|
|
||||||
import java.awt.event.ActionListener;
|
|
||||||
import javax.swing.JOptionPane;
|
|
||||||
|
|
||||||
|
|
||||||
public class PlayButtonClickListener implements ActionListener {
|
|
||||||
private Window window;
|
|
||||||
|
|
||||||
public PlayButtonClickListener(Window window) {
|
|
||||||
this.window = window;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
Button sourceButton = (Button) e.getSource();
|
|
||||||
String buttonText = sourceButton.getText();
|
|
||||||
|
|
||||||
if (buttonText.equals("Générer une grille")) {
|
|
||||||
Window.removeAllComponents(this.window);
|
|
||||||
new GridMakeUserInterfaceView(this.window);
|
|
||||||
}
|
|
||||||
else if (buttonText.equals("Jouer")) {
|
|
||||||
System.out.println("Bouton jouer presser");
|
|
||||||
} else if (buttonText.equals("Retour au menu principal")) {
|
|
||||||
if (window.getContentPane().getComponent(0) instanceof PlayMenuView) {
|
|
||||||
Window.removeAllComponents(window);
|
|
||||||
HomeView homeView = new HomeView(window);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,66 +0,0 @@
|
|||||||
import javax.swing.*;
|
|
||||||
import java.awt.*;
|
|
||||||
|
|
||||||
public class PlayMenuView extends JPanel {
|
|
||||||
|
|
||||||
// View components
|
|
||||||
private final Dimension BUTTON_SIZE = new Dimension(300, 60);
|
|
||||||
private final Color BACKGROUND_COLOR = new Color(54, 91, 109);
|
|
||||||
private final Color TITLE_TEXT_COLOR = Color.WHITE;
|
|
||||||
private final Font TITLE_FONT = new Font("Copperplate", Font.BOLD, 40);
|
|
||||||
private final Font BUTTON_FONT = new Font("Copperplate", Font.BOLD, 24);
|
|
||||||
private final String[] BUTTON_TEXTS = {"Jouer", "Générer une grille"};
|
|
||||||
private Title titleLabel;
|
|
||||||
private Button[] playModeButtons;
|
|
||||||
private Button returnButton;
|
|
||||||
private JPanel buttonPanel; // Declare buttonPanel here
|
|
||||||
|
|
||||||
// Constructor to initialize components
|
|
||||||
public PlayMenuView(Window window) {
|
|
||||||
createComponents(window);
|
|
||||||
addComponentsToWindow(window);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Method to create all components
|
|
||||||
private void createComponents(Window window) {
|
|
||||||
// Title
|
|
||||||
titleLabel = new Title("Choix du mode de jeu", TITLE_FONT, TITLE_TEXT_COLOR);
|
|
||||||
|
|
||||||
// Button Panel
|
|
||||||
GridLayout gestionnaireButtonPanel = new GridLayout(BUTTON_TEXTS.length, 1, 0, 10);
|
|
||||||
buttonPanel = new JPanel(gestionnaireButtonPanel); // Initialize buttonPanel here
|
|
||||||
buttonPanel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
|
|
||||||
buttonPanel.setBackground(BACKGROUND_COLOR);
|
|
||||||
|
|
||||||
// Buttons
|
|
||||||
playModeButtons = new Button[BUTTON_TEXTS.length];
|
|
||||||
for (int i = 0; i < BUTTON_TEXTS.length; i++) {
|
|
||||||
Button button = new Button(BUTTON_TEXTS[i], BUTTON_SIZE, BUTTON_FONT, BACKGROUND_COLOR);
|
|
||||||
playModeButtons[i] = button;
|
|
||||||
PlayButtonClickListener ecouteurBouton = new PlayButtonClickListener(window);
|
|
||||||
button.addActionListener(ecouteurBouton);
|
|
||||||
buttonPanel.add(button);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return Button
|
|
||||||
returnButton = new Button("Retour au menu principal", BUTTON_SIZE, BUTTON_FONT, BACKGROUND_COLOR);
|
|
||||||
returnButton.addActionListener(new PlayButtonClickListener(window));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Method to add components to the window
|
|
||||||
private void addComponentsToWindow(Window window) {
|
|
||||||
// Layout
|
|
||||||
window.setPageTitle("Menu jouer");
|
|
||||||
setLayout(new BorderLayout());
|
|
||||||
setBackground(BACKGROUND_COLOR);
|
|
||||||
|
|
||||||
// Adding components to the panel
|
|
||||||
add(titleLabel, BorderLayout.NORTH);
|
|
||||||
add(buttonPanel, BorderLayout.CENTER);
|
|
||||||
add(returnButton, BorderLayout.SOUTH);
|
|
||||||
|
|
||||||
|
|
||||||
// Add panel to the window
|
|
||||||
window.add(this);
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user