Correction de BEAUCOUP de bugs
This commit is contained in:
parent
fa0273f597
commit
8750448693
@ -1,4 +1,4 @@
|
||||
import javax.swing.JOptionPane;
|
||||
|
||||
|
||||
public interface DialogManager {
|
||||
void showDialog();
|
||||
|
@ -1,7 +1,6 @@
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.BorderLayout;
|
||||
import javax.swing.JOptionPane;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
@ -32,7 +31,8 @@ class HomeButtonClickListener implements ActionListener {
|
||||
String buttonText = ((Button) e.getSource()).getText();
|
||||
switch (buttonText) {
|
||||
case "Jouer":
|
||||
// à faire
|
||||
PlayMenuView playMenu = new PlayMenuView(window);
|
||||
window.changeMenu(playMenu);
|
||||
break;
|
||||
case "Règles":
|
||||
rulesDialogManager.showDialog();
|
||||
|
@ -17,21 +17,29 @@ public class HomeView extends JPanel {
|
||||
new Title("Sudoku Solver", TITLE_FONT, TITLE_TEXT_COLOR),
|
||||
new Title("Par Moncef & Marco", SUBTITLE_FONT, TITLE_TEXT_COLOR)
|
||||
};
|
||||
private final MusicButton musicButton;
|
||||
private Window window;
|
||||
private MusicButton musicButton;
|
||||
private final Window window;
|
||||
private JPanel titlePanel;
|
||||
private JPanel buttonPanel;
|
||||
private JLabel imageLabel;
|
||||
|
||||
public HomeView(Window window) {
|
||||
this.window = window;
|
||||
JPanel titlePanel = new JPanel();
|
||||
JPanel buttonPanel = new JPanel();
|
||||
createComponents();
|
||||
addComponentsToWindow();
|
||||
}
|
||||
|
||||
private void createComponents() {
|
||||
titlePanel = new JPanel();
|
||||
buttonPanel = new JPanel();
|
||||
ImageIcon iconeSudoku = new ImageIcon("img/sudoku.png");
|
||||
JLabel imageLabel = new JLabel(iconeSudoku);
|
||||
imageLabel = new JLabel(iconeSudoku);
|
||||
|
||||
GridLayout titleLayout = new GridLayout(2, 1);
|
||||
titlePanel.setLayout(titleLayout);
|
||||
titlePanel.setBackground(BACKGROUND_COLOR);
|
||||
// Utilisation de la classe Title pour le titre et le sous-titre
|
||||
for(Title label : labels){
|
||||
for (Title label : labels) {
|
||||
titlePanel.add(label);
|
||||
}
|
||||
|
||||
@ -47,22 +55,31 @@ public class HomeView extends JPanel {
|
||||
buttonPanel.add(button);
|
||||
}
|
||||
|
||||
BorderLayout layout = new BorderLayout();
|
||||
this.window.getContentPane().setLayout(layout);
|
||||
this.window.add(titlePanel, BorderLayout.NORTH);
|
||||
this.window.add(buttonPanel, BorderLayout.WEST);
|
||||
this.window.add(imageLabel, BorderLayout.EAST);
|
||||
this.window.setPageTitle("Menu");
|
||||
musicButton = new MusicButton(AUDIO_ON, AUDIO_OFF, MUSIC_FILE);
|
||||
}
|
||||
|
||||
public void addComponentsToWindow() {
|
||||
BorderLayout layout = new BorderLayout();
|
||||
window.getContentPane().setLayout(layout);
|
||||
window.add(titlePanel, BorderLayout.NORTH);
|
||||
window.add(buttonPanel, BorderLayout.WEST);
|
||||
window.add(imageLabel, BorderLayout.EAST);
|
||||
window.setPageTitle("Menu");
|
||||
|
||||
this.musicButton = new MusicButton(AUDIO_ON, AUDIO_OFF, MUSIC_FILE);
|
||||
FlowLayout controlPanelLayout = new FlowLayout(FlowLayout.RIGHT);
|
||||
JPanel controlPanel = new JPanel(controlPanelLayout);
|
||||
controlPanel.setBackground(BACKGROUND_COLOR);
|
||||
controlPanel.add(this.musicButton);
|
||||
this.window.add(controlPanel, BorderLayout.SOUTH);
|
||||
controlPanel.add(musicButton);
|
||||
window.add(controlPanel, BorderLayout.SOUTH);
|
||||
|
||||
this.window.pack();
|
||||
this.window.setLocationRelativeTo(null);
|
||||
this.window.setVisible(true);
|
||||
window.pack();
|
||||
window.setLocationRelativeTo(null);
|
||||
window.setVisible(true);
|
||||
}
|
||||
|
||||
public void removeAllComponents() {
|
||||
window.getContentPane().removeAll();
|
||||
window.revalidate();
|
||||
window.repaint();
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,3 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class Main{
|
||||
public static void main(String[] args) {
|
||||
Window fenetre = new Window(); // Création d'une fenêtre
|
||||
|
@ -1,25 +1,19 @@
|
||||
import java.awt.*;
|
||||
import javax.swing.*;
|
||||
|
||||
/**
|
||||
* A custom JButton designed to control music playback.
|
||||
* It provides a button that toggles between playing and stopping music when clicked.
|
||||
*
|
||||
* @version 1.0
|
||||
* @author Moncef STITI
|
||||
* @author Marco ORFAO
|
||||
*/
|
||||
|
||||
public class MusicButton extends JButton {
|
||||
private boolean isMusicOn;
|
||||
public class MusicButton extends JButton {
|
||||
private static MusicPlayer currentMusicPlayer;
|
||||
private ImageIcon iconOn;
|
||||
private ImageIcon iconOff;
|
||||
private MusicPlayer musicPlayer;
|
||||
|
||||
|
||||
/**
|
||||
* Constructs a MusicButton.
|
||||
*
|
||||
* @param onIconPath The file path for the icon when music is on.
|
||||
* @param offIconPath The file path for the icon when music is off.
|
||||
* @param musicFilePath The file path for the music file to be played.
|
||||
@ -29,18 +23,25 @@ public class MusicButton extends JButton {
|
||||
this.iconOn = new ImageIcon(onIconPath);
|
||||
this.iconOff = new ImageIcon(offIconPath);
|
||||
setIcon(this.iconOff);
|
||||
this.isMusicOn = false;
|
||||
|
||||
// Vérifie s'il y a déjà une musique en cours de lecture et l'arrête si nécessaire
|
||||
if (currentMusicPlayer != null && currentMusicPlayer.isPlaying()) {
|
||||
currentMusicPlayer.stop();
|
||||
currentMusicPlayer = null;
|
||||
}
|
||||
|
||||
this.musicPlayer = new MusicPlayer(musicFilePath);
|
||||
|
||||
addActionListener(e -> {
|
||||
if (this.isMusicOn) {
|
||||
this.musicPlayer.stop();
|
||||
if (currentMusicPlayer != null && currentMusicPlayer.isPlaying()) {
|
||||
currentMusicPlayer.stop();
|
||||
currentMusicPlayer = null;
|
||||
setIcon(this.iconOff);
|
||||
} else {
|
||||
this.musicPlayer.play();
|
||||
setIcon(this.iconOn);
|
||||
currentMusicPlayer = this.musicPlayer;
|
||||
}
|
||||
this.isMusicOn = !this.isMusicOn;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,6 @@ public class MusicPlayer {
|
||||
|
||||
/**
|
||||
* Constructs a MusicPlayer with the specified file path.
|
||||
*
|
||||
* @param filePath The path to the music file to be played.
|
||||
*/
|
||||
public MusicPlayer(String filePath) {
|
||||
@ -50,7 +49,6 @@ public class MusicPlayer {
|
||||
|
||||
/**
|
||||
* Checks if the music is currently playing.
|
||||
*
|
||||
* @return true if the music is playing, false otherwise.
|
||||
*/
|
||||
public boolean isPlaying() {
|
||||
|
29
src/PlayButtonClickListener.java
Normal file
29
src/PlayButtonClickListener.java
Normal file
@ -0,0 +1,29 @@
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
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();
|
||||
|
||||
// Handle different button actions based on their text
|
||||
if (buttonText.equals("Générer une grille")) {
|
||||
System.out.println("Générer une grille");
|
||||
} else if (buttonText.equals("Charger une grille")) {
|
||||
System.out.println("Chargement de la grille");
|
||||
} else if (buttonText.equals("Retour au menu principal")) {
|
||||
if (window.getContentPane().getComponent(0) instanceof PlayMenuView) {
|
||||
PlayMenuView playMenuView = (PlayMenuView) window.getContentPane().getComponent(0);
|
||||
playMenuView.removeAllComponents(window);
|
||||
HomeView homeView = new HomeView(window);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -2,5 +2,70 @@ import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class PlayMenuView extends JPanel {
|
||||
// à faire
|
||||
|
||||
// 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 = {"Générer une grille", "Charger 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;
|
||||
button.addActionListener(new PlayButtonClickListener(window));
|
||||
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
|
||||
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);
|
||||
}
|
||||
|
||||
// Method to remove all components from the window
|
||||
public void removeAllComponents(Window window) {
|
||||
window.remove(this);
|
||||
window.revalidate();
|
||||
window.repaint();
|
||||
}
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ public class Window extends JFrame {
|
||||
public Window() {
|
||||
super(PROGRAM_TITLE);
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
this.setMinimumSize(this.MIN_WINDOW_SIZE);
|
||||
this.setMinimumSize(MIN_WINDOW_SIZE);
|
||||
this.setLocationRelativeTo(null);
|
||||
getContentPane().setBackground(new Color(54, 91, 109));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user