From 82fa866cb8d67a619fbd0216f550867273ffa551 Mon Sep 17 00:00:00 2001 From: follea Date: Fri, 26 Apr 2024 23:43:45 +0200 Subject: [PATCH] =?UTF-8?q?Cr=C3=A9ation=20de=20la=20fenetre=20avec=20ajou?= =?UTF-8?q?t=20de=20la=20grille=20en=209*9=20case?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SudokuGrid.java | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 SudokuGrid.java diff --git a/SudokuGrid.java b/SudokuGrid.java new file mode 100644 index 0000000..50925de --- /dev/null +++ b/SudokuGrid.java @@ -0,0 +1,43 @@ +import javax.swing.*; +import java.awt.*; +import java.awt.event.*; + +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(new Color(0, 255, 0)); // Fond vert + + // Initialiser le grid + 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(); + grid[i][j].setHorizontalAlignment(JTextField.CENTER); + gridPanel.add(grid[i][j]); + } + } + + // Panneau pour les boutons + JPanel buttonPanel = new JPanel(); + buttonPanel.setBackground(new Color(0, 255, 0)); // Fond vert + buttonPanel.setPreferredSize(new Dimension(100, 0)); // Espace pour les bouton + + // Ajout des panneaux à la fenetre + getContentPane().add(gridPanel, BorderLayout.CENTER); + getContentPane().add(buttonPanel, BorderLayout.EAST); + } + + public static void main(String[] args) { + // afficage et création de la fenetre + SudokuGrid sudokuGrid = new SudokuGrid(); + sudokuGrid.setSize(700,600); + sudokuGrid.setLocation(100, 100); + sudokuGrid.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + sudokuGrid.setVisible(true); + } +}