diff --git a/audio/musiqueDeFond.wav b/audio/musiqueDeFond.wav new file mode 100644 index 0000000..f00f883 Binary files /dev/null and b/audio/musiqueDeFond.wav differ diff --git a/img/iconeAudio.png b/img/iconeAudio.png new file mode 100644 index 0000000..e3733d6 Binary files /dev/null and b/img/iconeAudio.png differ diff --git a/img/iconeAudioMuted.png b/img/iconeAudioMuted.png new file mode 100644 index 0000000..4bf28c6 Binary files /dev/null and b/img/iconeAudioMuted.png differ diff --git a/src/Button.java b/src/Button.java new file mode 100644 index 0000000..3930148 --- /dev/null +++ b/src/Button.java @@ -0,0 +1,61 @@ +import javax.swing.*; +import java.awt.*; + +/** + * Class containing custom settings for JButtons used in the application. + * @version 1.0 + * @author Moncef STITI + * @author Marco ORFAO + */ + +public class Button extends JButton { + /** + * Constructor + * @param text The text of the button + */ + public Button (String text) { + super(text); + setFont(new Font("Arial", Font.BOLD, 15)); + setBackground(new Color(96, 175, 255)); + } + + /** + * Constructor + * @param text The text of the button + * @param dimension The dimension of the button + */ + public Button(String text, Dimension dimension) { + super(text); + setPreferredSize(dimension); + setFont(new Font("Arial", Font.BOLD, 20)); + setBackground(new Color(96, 175, 255)); + } + + /** + * Constructor + * @param text The text of the button + * @param dimension The dimension of the button + * @param font The font of the text in the button + */ + public Button(String text, Dimension dimension, Font font) { + super(text); + setPreferredSize(dimension); + setFont(font); + setBackground(new Color(96, 175, 255)); + } + + /** + * Constructor + * @param text The text of the button + * @param dimension The dimension of the button + * @param font The font of the text in the button + * @param color The background color of the button + */ + public Button(String text, Dimension dimension, Font font, Color color) { + super(text); + setPreferredSize(dimension); + setFont(font); + setBackground(color); + } + +} \ No newline at end of file diff --git a/src/Main.java b/src/Main.java new file mode 100644 index 0000000..0793808 --- /dev/null +++ b/src/Main.java @@ -0,0 +1,5 @@ +public class Main{ + public static void main(String[] args) { + MenuView menu = new MenuView(); + } +} \ No newline at end of file diff --git a/src/Menu.java b/src/MenuView.java similarity index 53% rename from src/Menu.java rename to src/MenuView.java index 0d6d3a5..ac39062 100644 --- a/src/Menu.java +++ b/src/MenuView.java @@ -1,30 +1,45 @@ import javax.swing.*; import java.awt.*; -public class Menu extends JFrame { - // Attributs +/** + * A menu view for a Sudoku application. + * @version 1.0 + * @author Moncef STITI + * @author Marco ORFAO + */ + +public class MenuView extends JFrame { + private String scheminIconAudio = new String("../img/iconeAudio.png"); + private String scheminIconAudioMuted = new String("../img/iconeAudioMuted.png"); + private String scheminMusique = new String("../audio/musiqueDeFond.wav"); + private ImageIcon iconAudio = new ImageIcon(scheminIconAudio); + private ImageIcon iconAudioMuted = new ImageIcon(scheminIconAudioMuted); + private ImageIcon imageSudoku = new ImageIcon("../img/sudoku.png"); // Image Sudoku + private Dimension tailleFenetre = new Dimension(1000,700); // Taille de la fenêtre private Dimension tailleBouton = new Dimension(300, 60); // Taille des boutons private Color couleurFond = new Color(54, 91, 109); // Couleur du fond de la fenêtre private Color couleurTexteTitre = Color.WHITE; // Couleur du texte du titre et sous-titre - private int tailleTitre = 75; // Taille du texte du titre - private int tailleSousTitre = 24; // Taille du texte du sous-titre - private int tailleTexteBouton = 24; // Taille du texte des boutons - private Dimension tailleFenetre = new Dimension(1000,700); // Taille de la fenêtre - private Font policeTitre = new Font("Copperplate", Font.BOLD, tailleTitre); // Police du titre - private Font policeSousTitre = new Font("Copperplate", Font.PLAIN, tailleSousTitre); // Police du sous-titre - private Font policeBouton = new Font("Copperplate", Font.BOLD, tailleTexteBouton); // Police des boutons + private Font policeTitre = new Font("Copperplate", Font.BOLD, 75); // Police du titre + private Font policeSousTitre = new Font("Copperplate", Font.PLAIN, 24); // Police du sous-titre + private Font policeBouton = new Font("Copperplate", Font.BOLD, 24); // Police des boutons private String[] boutonTextes = {"Jouer", "Générer une grille", "Résoudre une grille", "Quitter"}; // Textes des boutons - private JLabel[] labels = {new JLabel("Sudoku Solver", SwingConstants.CENTER), // Texte du titre et sous-titre - new JLabel("Par Moncef & Marco", SwingConstants.CENTER)}; + private JLabel[] labels = {new JLabel("Sudoku Solver", SwingConstants.CENTER), // Texte du titre + new JLabel("Par Moncef & Marco", SwingConstants.CENTER)}; // Texte du sous-titre - // Constructeurs - public Menu() { - // Création et configuration de la fenêtre (taille, fermeture) + + + /** + * Constructs a MenuView. + * Initializes and configures the menu window with buttons and controls. + */ + public MenuView() { + // Création et configuration de la fenêtre JFrame fenetre = new JFrame("Sudoku - Menu principal"); fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); fenetre.setMinimumSize(tailleFenetre); fenetre.getContentPane().setBackground(couleurFond); - fenetre.setLayout(new BorderLayout()); + BorderLayout gestionnaireBorderLayout = new BorderLayout(); + fenetre.setLayout(gestionnaireBorderLayout); // Création et ajout du panneau de titre JPanel panneauTitre = new JPanel(new GridLayout(2, 1)); @@ -40,32 +55,31 @@ public class Menu extends JFrame { // Création et ajout du panneau de boutons JPanel panneauBouton = new JPanel(); - panneauBouton.setLayout(new GridLayout(boutonTextes.length, 1, 0, 10)); - panneauBouton.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20)); // Permet de ne pas coller les boutons aux bords de la fenêtre + GridLayout gestionnairePanneauBouton = new GridLayout(boutonTextes.length, 1, 0, 10); + panneauBouton.setLayout(gestionnairePanneauBouton); + panneauBouton.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20)); panneauBouton.setBackground(couleurFond); - JButton[] boutons = new JButton[boutonTextes.length]; + Button[] boutons = new Button[boutonTextes.length]; for (int i = 0; i < boutons.length; i++) { - boutons[i] = new JButton(boutonTextes[i]); - boutons[i].setFont(policeBouton); - boutons[i].setPreferredSize(tailleBouton); + boutons[i] = new Button(boutonTextes[i], tailleBouton, policeBouton, couleurFond); panneauBouton.add(boutons[i]); } fenetre.add(panneauBouton, BorderLayout.WEST); // Ajout de l'image "sudoku.png" - ImageIcon imageSudoku = new ImageIcon("../img/sudoku.png"); JLabel imageLabel = new JLabel(imageSudoku); fenetre.add(imageLabel, BorderLayout.EAST); + // Ajout du bouton de contrôle de la musique + MusicButton musicButton = new MusicButton(scheminIconAudio, scheminIconAudioMuted, scheminMusique); + FlowLayout gestionnaireControlPanel = new FlowLayout(FlowLayout.RIGHT); + JPanel controlPanel = new JPanel(gestionnaireControlPanel); + controlPanel.setBackground(couleurFond); + controlPanel.add(musicButton); + fenetre.add(controlPanel, BorderLayout.SOUTH); + fenetre.pack(); fenetre.setLocationRelativeTo(null); fenetre.setVisible(true); } - - /* À SUPPRIMER APRÈS LA PHASE DE DEBUG - public static void main(String[] args) { - Menu menu = new Menu(); - } - */ - -} +} \ No newline at end of file diff --git a/src/MusicButton.java b/src/MusicButton.java new file mode 100644 index 0000000..97eeb26 --- /dev/null +++ b/src/MusicButton.java @@ -0,0 +1,47 @@ +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; + 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. + */ + + public MusicButton(String onIconPath, String offIconPath, String musicFilePath) { + + iconOn = new ImageIcon(onIconPath); + iconOff = new ImageIcon(offIconPath); + setIcon(iconOff); + isMusicOn = false; + musicPlayer = new MusicPlayer(musicFilePath); + + addActionListener(e -> { + if (isMusicOn) { + musicPlayer.stop(); + setIcon(iconOff); + } else { + musicPlayer.play(); + setIcon(iconOn); + } + isMusicOn = !isMusicOn; + }); + } +} diff --git a/src/MusicPlayer.java b/src/MusicPlayer.java new file mode 100644 index 0000000..137f040 --- /dev/null +++ b/src/MusicPlayer.java @@ -0,0 +1,59 @@ +import java.io.File; +import javax.sound.sampled.*; + +/** + * Class containign a simple music player that allows playing and stopping music. + * @version 1.0 + * @author Moncef STITI + * @author Marco ORFAO + */ + +public class MusicPlayer { + private Clip clip; + private boolean isPlaying; + + /** + * Constructs a MusicPlayer with the specified file path. + * + * @param filePath The path to the music file to be played. + */ + public MusicPlayer(String filePath) { + try { + File file = new File(filePath); + AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(file); + clip = AudioSystem.getClip(); + clip.open(audioInputStream); + } catch (Exception e) { + e.printStackTrace(); + } + } + + /** + * Starts playing the music. + */ + public void play() { + if (clip != null && !isPlaying) { + clip.start(); + isPlaying = true; + } + } + + /** + * Stops the music. + */ + public void stop() { + if (clip != null && isPlaying) { + clip.stop(); + isPlaying = false; + } + } + + /** + * Checks if the music is currently playing. + * + * @return true if the music is playing, false otherwise. + */ + public boolean isPlaying() { + return isPlaying; + } +}