Modification des paramètre d'affichage de la grille

This commit is contained in:
Daouadi Amir 2023-04-20 12:14:47 +02:00
parent 31ceafcacc
commit 4c2b64e49c
12 changed files with 17 additions and 13 deletions

Binary file not shown.

Binary file not shown.

View File

@ -7,6 +7,7 @@ public class Boutons extends JPanel {
private JButton choisirGrille; private JButton choisirGrille;
private JButton importerGrille; private JButton importerGrille;
private JFrame fenetrePrincipale; private JFrame fenetrePrincipale;
/*private int tailleGrille; // variable pour stocker la taille de la grille choisie par l'utilisateur */
public Boutons(JFrame fenetrePrincipale) { public Boutons(JFrame fenetrePrincipale) {
// Création des boutons // Création des boutons
@ -32,16 +33,18 @@ public class Boutons extends JPanel {
} }
try { try {
int taille = Integer.parseInt(strTaille); int taille = Integer.parseInt(strTaille);
if (taille > 3 && taille < 21) { if (taille > 3 && taille < 21) {
// afficher la taille choisir dans la console // stocker la taille de la grille choisie
System.out.println("Les dimensions de la grille : " + taille + "x" + taille); /*this.tailleGrille = taille;*/
// Afficher la boîte de dialogue pour le choix du remplissage de la grille // afficher la taille choisir dans la console
String[] options = {"Remplir aléatoirement", "Partir d'une grille vide"}; System.out.println("Les dimensions de la grille : " + taille + "x" + taille);
int choix = JOptionPane.showOptionDialog(this, "Choisissez comment remplir la grille :", "Remplissage de la grille", JOptionPane.DEFAULT_OPTION, JOptionPane.PLAIN_MESSAGE, null, options, options[0]); // Afficher la boîte de dialogue pour le choix du remplissage de la grille
switch (choix) { String[] options = {"Remplir aléatoirement", "Partir d'une grille vide"};
int choix = JOptionPane.showOptionDialog(this, "Choisissez comment remplir la grille :", "Remplissage de la grille", JOptionPane.DEFAULT_OPTION, JOptionPane.PLAIN_MESSAGE, null, options, options[0]);
switch (choix) {
case 0: case 0:
// afficher la grille aléatoirement // afficher la grille aléatoirement
GridPanel grille = new GridPanel(); GridPanel grille = new GridPanel(taille);
this.fenetrePrincipale.add(grille); this.fenetrePrincipale.add(grille);
this.fenetrePrincipale.validate(); this.fenetrePrincipale.validate();
break; break;

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -4,7 +4,7 @@ import java.util.Random;
import java.awt.event.*; import java.awt.event.*;
public class GridPanel extends JPanel { public class GridPanel extends JPanel {
private int gridSize = 10; private int gridSize;
private int cellSize = 50; private int cellSize = 50;
private Color[][] gridColors; private Color[][] gridColors;
private boolean editMode = false; private boolean editMode = false;
@ -16,7 +16,8 @@ public class GridPanel extends JPanel {
private JButton placeTButton; private JButton placeTButton;
private JButton editButton; private JButton editButton;
public GridPanel() { public GridPanel(int gs) {
this.gridSize = gs;
setPreferredSize(new Dimension(gridSize * cellSize, gridSize * cellSize)); setPreferredSize(new Dimension(gridSize * cellSize, gridSize * cellSize));
setBackground(Color.WHITE); setBackground(Color.WHITE);
@ -135,7 +136,7 @@ public void paintComponent(Graphics g) {
} }
public static void main(String[] args) { /*public static void main(String[] args) {
JFrame frame = new JFrame("GridPanel"); JFrame frame = new JFrame("GridPanel");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(new BorderLayout()); frame.getContentPane().setLayout(new BorderLayout());
@ -144,5 +145,5 @@ public static void main(String[] args) {
frame.getContentPane().add(gridPanel.getComponents()[0], BorderLayout.NORTH); frame.getContentPane().add(gridPanel.getComponents()[0], BorderLayout.NORTH);
frame.pack(); frame.pack();
frame.setVisible(true); frame.setVisible(true);
} }*/
} }