2024-04-09 17:13:23 +02:00
|
|
|
import javax.swing.*;
|
|
|
|
import java.awt.*;
|
|
|
|
|
|
|
|
public class HomeView extends JPanel {
|
|
|
|
|
|
|
|
private final String AUDIO_ON = "img/iconeAudio.png";
|
|
|
|
private final String AUDIO_OFF = "img/iconeAudioMuted.png";
|
|
|
|
private final String MUSIC_FILE = "audio/musiqueDeFond.wav";
|
|
|
|
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, 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 Title[] labels = {
|
2024-04-09 23:28:32 +02:00
|
|
|
new Title("Sudoku Solver", TITLE_FONT, TITLE_TEXT_COLOR),
|
|
|
|
new Title("Par Moncef & Marco", SUBTITLE_FONT, TITLE_TEXT_COLOR)
|
|
|
|
};
|
|
|
|
private MusicButton musicButton;
|
|
|
|
private final Window window;
|
|
|
|
private JPanel titlePanel;
|
|
|
|
private JPanel buttonPanel;
|
|
|
|
private JLabel imageLabel;
|
2024-04-09 17:13:23 +02:00
|
|
|
|
|
|
|
public HomeView(Window window) {
|
|
|
|
this.window = window;
|
2024-04-09 23:28:32 +02:00
|
|
|
createComponents();
|
|
|
|
addComponentsToWindow();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void createComponents() {
|
|
|
|
titlePanel = new JPanel();
|
|
|
|
buttonPanel = new JPanel();
|
2024-04-09 17:13:23 +02:00
|
|
|
ImageIcon iconeSudoku = new ImageIcon("img/sudoku.png");
|
2024-04-09 23:28:32 +02:00
|
|
|
imageLabel = new JLabel(iconeSudoku);
|
2024-04-09 17:13:23 +02:00
|
|
|
|
|
|
|
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
|
2024-04-09 23:28:32 +02:00
|
|
|
for (Title label : labels) {
|
2024-04-09 17:13:23 +02:00
|
|
|
titlePanel.add(label);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Button Panel
|
|
|
|
GridLayout buttonLayout = new GridLayout(BUTTON_TEXTS.length, 1, 0, 10);
|
|
|
|
buttonPanel.setLayout(buttonLayout);
|
|
|
|
buttonPanel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
|
|
|
|
buttonPanel.setBackground(BACKGROUND_COLOR);
|
|
|
|
HomeButtonClickListener listenerButton = new HomeButtonClickListener(window);
|
|
|
|
for (String text : BUTTON_TEXTS) {
|
|
|
|
Button button = new Button(text, BUTTON_SIZE, BUTTON_FONT, BACKGROUND_COLOR);
|
|
|
|
button.addActionListener(listenerButton);
|
|
|
|
buttonPanel.add(button);
|
|
|
|
}
|
|
|
|
|
2024-04-09 23:28:32 +02:00
|
|
|
musicButton = new MusicButton(AUDIO_ON, AUDIO_OFF, MUSIC_FILE);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void addComponentsToWindow() {
|
2024-04-09 17:13:23 +02:00
|
|
|
BorderLayout layout = new BorderLayout();
|
2024-04-09 23:28:32 +02:00
|
|
|
window.getContentPane().setLayout(layout);
|
|
|
|
window.add(titlePanel, BorderLayout.NORTH);
|
|
|
|
window.add(buttonPanel, BorderLayout.WEST);
|
|
|
|
window.add(imageLabel, BorderLayout.EAST);
|
|
|
|
window.setPageTitle("Menu");
|
2024-04-09 17:13:23 +02:00
|
|
|
|
|
|
|
FlowLayout controlPanelLayout = new FlowLayout(FlowLayout.RIGHT);
|
|
|
|
JPanel controlPanel = new JPanel(controlPanelLayout);
|
|
|
|
controlPanel.setBackground(BACKGROUND_COLOR);
|
2024-04-09 23:28:32 +02:00
|
|
|
controlPanel.add(musicButton);
|
|
|
|
window.add(controlPanel, BorderLayout.SOUTH);
|
|
|
|
|
|
|
|
window.pack();
|
|
|
|
window.setLocationRelativeTo(null);
|
|
|
|
window.setVisible(true);
|
|
|
|
}
|
2024-04-09 17:13:23 +02:00
|
|
|
|
2024-04-09 23:28:32 +02:00
|
|
|
public void removeAllComponents() {
|
|
|
|
window.getContentPane().removeAll();
|
|
|
|
window.revalidate();
|
|
|
|
window.repaint();
|
2024-04-09 17:13:23 +02:00
|
|
|
}
|
|
|
|
}
|