Création de la fenetre avec ajout de la grille en 9*9 case
This commit is contained in:
43
SudokuGrid.java
Normal file
43
SudokuGrid.java
Normal file
@@ -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);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user