From a1ae3bdc4349703c8c65689e06b7c2dc80e2759a Mon Sep 17 00:00:00 2001 From: stiti Date: Wed, 17 Apr 2024 14:57:42 +0200 Subject: [PATCH] Modification des menus --- src/HomeButtonClickListener.java | 17 ++++---- src/HomeView.java | 2 +- src/HowToPlayDialogManager.java | 9 ----- src/HowToPlaySudoku.java | 34 ---------------- src/PlayButtonClickListener.java | 31 --------------- src/PlayMenuView.java | 66 -------------------------------- 6 files changed, 10 insertions(+), 149 deletions(-) delete mode 100644 src/HowToPlayDialogManager.java delete mode 100644 src/HowToPlaySudoku.java delete mode 100644 src/PlayButtonClickListener.java delete mode 100644 src/PlayMenuView.java diff --git a/src/HomeButtonClickListener.java b/src/HomeButtonClickListener.java index 45f3ae7..fa64ceb 100644 --- a/src/HomeButtonClickListener.java +++ b/src/HomeButtonClickListener.java @@ -4,11 +4,13 @@ import java.awt.event.ActionListener; /** * Listener for button clicks in the menu. * It performs different actions based on the button clicked. + * @version 1.0 + * @author Moncef STITI + * @author Marco ORFAO */ class HomeButtonClickListener implements ActionListener { private Window window; private DialogManager rulesDialogManager; - private DialogManager howToPlayDialogManager; /** * Constructs a ButtonClickListener with the specified window. @@ -17,7 +19,6 @@ class HomeButtonClickListener implements ActionListener { public HomeButtonClickListener(Window window) { this.window = window; this.rulesDialogManager = new RulesDialogManager(); - this.howToPlayDialogManager = new HowToPlayDialogManager(); } /** @@ -29,14 +30,14 @@ class HomeButtonClickListener implements ActionListener { String buttonText = ((Button) e.getSource()).getText(); switch (buttonText) { case "Jouer": - PlayMenuView playMenu = new PlayMenuView(window); - window.changeMenu(playMenu); + System.out.println("Bouton jouer cliquer"); // lancer jeu + 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; case "Règles": - rulesDialogManager.showDialog(); - break; - case "Comment jouer ?": - howToPlayDialogManager.showDialog(); + rulesDialogManager.showDialog(); // Afficher les règles break; case "Quitter": System.exit(0); // Quitter le programme diff --git a/src/HomeView.java b/src/HomeView.java index 9a428ad..c343a64 100644 --- a/src/HomeView.java +++ b/src/HomeView.java @@ -12,7 +12,7 @@ public class HomeView extends JPanel { 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 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 = { new Title("Sudoku Solver", TITLE_FONT, TITLE_TEXT_COLOR), new Title("Par Moncef & Marco", SUBTITLE_FONT, TITLE_TEXT_COLOR) diff --git a/src/HowToPlayDialogManager.java b/src/HowToPlayDialogManager.java deleted file mode 100644 index c22ff52..0000000 --- a/src/HowToPlayDialogManager.java +++ /dev/null @@ -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); - } -} \ No newline at end of file diff --git a/src/HowToPlaySudoku.java b/src/HowToPlaySudoku.java deleted file mode 100644 index 6771300..0000000 --- a/src/HowToPlaySudoku.java +++ /dev/null @@ -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 - } -} diff --git a/src/PlayButtonClickListener.java b/src/PlayButtonClickListener.java deleted file mode 100644 index bb363d5..0000000 --- a/src/PlayButtonClickListener.java +++ /dev/null @@ -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); - } - } - } -} diff --git a/src/PlayMenuView.java b/src/PlayMenuView.java deleted file mode 100644 index 3eeb1f9..0000000 --- a/src/PlayMenuView.java +++ /dev/null @@ -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); - } -}