60 lines
1.8 KiB
Java
60 lines
1.8 KiB
Java
import javax.swing.*;
|
|
import java.awt.*;
|
|
|
|
public class SudokuGrid extends JFrame {
|
|
private static final int GRID_SIZE = 9; // Taille de la grille Sudoku 9x9
|
|
private JTextField[][] grid;
|
|
|
|
public SudokuGrid() {
|
|
// Panneau pour la grille Sudoku
|
|
JPanel gridPanel = new JPanel();
|
|
gridPanel.setLayout(new GridLayout(GRID_SIZE, GRID_SIZE)); // Utiliser GridLayout
|
|
gridPanel.setBackground(Color.black); // Fond vert
|
|
|
|
// Initialiser la grille
|
|
grid = new JTextField[GRID_SIZE][GRID_SIZE];
|
|
for (int i = 0; i < GRID_SIZE; i++) {
|
|
for (int j = 0; j < GRID_SIZE; j++) {
|
|
grid[i][j] = new JTextField();
|
|
|
|
TextFilter filtre = new TextFilter(grid[i][j]);
|
|
|
|
grid[i][j].addKeyListener(filtre);
|
|
grid[i][j].setHorizontalAlignment(JTextField.CENTER);
|
|
grid[i][j].setFont(new Font("Verdana", Font.BOLD,40));
|
|
gridPanel.add(grid[i][j]);
|
|
}
|
|
}
|
|
|
|
// Panneau pour les boutons
|
|
JPanel bouton = new JPanel();
|
|
bouton.setBackground(new Color(88, 169, 191)); // Fond vert
|
|
bouton.setPreferredSize(new Dimension(150, 0)); // Espace pour les boutons
|
|
|
|
// Bouton pour sauvegarder la grille
|
|
JButton save = new JButton("Sauvegarder");
|
|
|
|
SaveButton saver = new SaveButton(GRID_SIZE,grid);
|
|
|
|
save.addActionListener(saver);
|
|
|
|
|
|
// Bouton pour chargé la grille
|
|
JButton load = new JButton("Charger");
|
|
|
|
LoadButton loader = new LoadButton(GRID_SIZE, grid);
|
|
|
|
load.addActionListener(loader);
|
|
|
|
bouton.add(load);
|
|
bouton.add(save);
|
|
|
|
// Ajout des panneaux à la fenetre
|
|
getContentPane().add(gridPanel, BorderLayout.CENTER);
|
|
getContentPane().add(bouton, BorderLayout.EAST);
|
|
}
|
|
|
|
|
|
|
|
}
|