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,7 +7,8 @@ public class Boutons extends JPanel {
private JButton choisirGrille;
private JButton importerGrille;
private JFrame fenetrePrincipale;
/*private int tailleGrille; // variable pour stocker la taille de la grille choisie par l'utilisateur */
public Boutons(JFrame fenetrePrincipale) {
// Création des boutons
choisirGrille = new JButton("Générer une grille");
@ -32,16 +33,18 @@ public class Boutons extends JPanel {
}
try {
int taille = Integer.parseInt(strTaille);
if (taille > 3 && taille < 21) {
// afficher la taille choisir dans la console
System.out.println("Les dimensions de la grille : " + taille + "x" + taille);
// Afficher la boîte de dialogue pour le choix du remplissage de la grille
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) {
if (taille > 3 && taille < 21) {
// stocker la taille de la grille choisie
/*this.tailleGrille = taille;*/
// afficher la taille choisir dans la console
System.out.println("Les dimensions de la grille : " + taille + "x" + taille);
// Afficher la boîte de dialogue pour le choix du remplissage de la grille
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:
// afficher la grille aléatoirement
GridPanel grille = new GridPanel();
GridPanel grille = new GridPanel(taille);
this.fenetrePrincipale.add(grille);
this.fenetrePrincipale.validate();
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.*;
public class GridPanel extends JPanel {
private int gridSize = 10;
private int gridSize;
private int cellSize = 50;
private Color[][] gridColors;
private boolean editMode = false;
@ -16,7 +16,8 @@ public class GridPanel extends JPanel {
private JButton placeTButton;
private JButton editButton;
public GridPanel() {
public GridPanel(int gs) {
this.gridSize = gs;
setPreferredSize(new Dimension(gridSize * cellSize, gridSize * cellSize));
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");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(new BorderLayout());
@ -144,5 +145,5 @@ public static void main(String[] args) {
frame.getContentPane().add(gridPanel.getComponents()[0], BorderLayout.NORTH);
frame.pack();
frame.setVisible(true);
}
}*/
}