117 lines
4.0 KiB
Java
117 lines
4.0 KiB
Java
import javax.swing.*;
|
|
import java.awt.*;
|
|
import java.util.Random;
|
|
import javax.swing.border.Border;
|
|
|
|
public class FenetreRndmGrille extends Fenetre{
|
|
private int[] tab_de_int;
|
|
private int Taille;
|
|
private int ValeurEntre;
|
|
private int ValeurSortie;
|
|
|
|
private JPanel[][] TabDePanel;
|
|
|
|
public FenetreRndmGrille(int Taille){
|
|
super();
|
|
this.tab_de_int = new int[] {1, 1};
|
|
this.Taille = Taille;
|
|
this.TabDePanel = new JPanel[this.Taille][this.Taille];
|
|
}
|
|
|
|
protected void RandomGrille(){
|
|
this.fenetre.setSize(600, 600);
|
|
this.fenetre.setLocation(450, 200);
|
|
|
|
GridLayout gestionnaire = new GridLayout(this.Taille,this.Taille);
|
|
this.fenetre.setLayout(gestionnaire);
|
|
|
|
OptionsFRG un_Test = new OptionsFRG(this);
|
|
un_Test.SetUp();
|
|
|
|
Random rand = new Random();
|
|
this.ValeurEntre = rand.nextInt(this.Taille*this.Taille);
|
|
this.ValeurSortie = rand.nextInt(this.Taille*this.Taille);
|
|
if(this.ValeurSortie == this.ValeurEntre){
|
|
while(this.ValeurSortie == this.ValeurEntre)
|
|
{
|
|
this.ValeurSortie = rand.nextInt(this.Taille*this.Taille);
|
|
}
|
|
}
|
|
|
|
int compteur=0;
|
|
|
|
for(int i=0; i<Taille; i++){
|
|
for(int j=0; j<Taille; j++){
|
|
int nombreAleatoire = rand.nextInt(3); // génère un nombre entre 0 et 10
|
|
|
|
JPanel ce_panel = new JPanel();
|
|
this.TabDePanel[j][i] = ce_panel;
|
|
|
|
if(compteur==this.ValeurEntre){
|
|
Border border = BorderFactory.createLineBorder(Color.BLACK, 1);
|
|
ce_panel.setBorder(border);
|
|
ce_panel.setBackground(Color.BLUE);
|
|
this.fenetre.add(ce_panel);
|
|
|
|
ModificationsFRG testee = new ModificationsFRG(un_Test, this.tab_de_int);
|
|
ce_panel.addMouseListener(testee);
|
|
|
|
this.tab_de_int=testee.getValues();
|
|
|
|
} else if(compteur==this.ValeurSortie){
|
|
Border border = BorderFactory.createLineBorder(Color.BLACK, 1);
|
|
ce_panel.setBorder(border);
|
|
ce_panel.setBackground(Color.RED);
|
|
this.fenetre.add(ce_panel);
|
|
|
|
ModificationsFRG testee = new ModificationsFRG(un_Test, this.tab_de_int);
|
|
ce_panel.addMouseListener(testee);
|
|
|
|
this.tab_de_int=testee.getValues();
|
|
|
|
} else if(nombreAleatoire == 0){
|
|
Border border = BorderFactory.createLineBorder(Color.BLACK, 1);
|
|
ce_panel.setBorder(border);
|
|
ce_panel.setBackground(Color.BLACK);
|
|
this.fenetre.add(ce_panel);
|
|
|
|
ModificationsFRG testee = new ModificationsFRG(un_Test, this.tab_de_int);
|
|
ce_panel.addMouseListener(testee);
|
|
|
|
this.tab_de_int=testee.getValues();
|
|
|
|
} else{
|
|
Border border = BorderFactory.createLineBorder(Color.BLACK, 1);
|
|
ce_panel.setBorder(border);
|
|
ce_panel.setBackground(Color.WHITE);
|
|
this.fenetre.add(ce_panel);
|
|
|
|
ModificationsFRG testee = new ModificationsFRG(un_Test, this.tab_de_int);
|
|
ce_panel.addMouseListener(testee);
|
|
|
|
this.tab_de_int=testee.getValues();
|
|
}
|
|
|
|
compteur++;
|
|
|
|
}
|
|
}
|
|
|
|
this.fenetre.setVisible(true);
|
|
}
|
|
|
|
protected int[] get_info(){
|
|
int[] infos_grille = new int[5];
|
|
infos_grille[0] = this.Taille;
|
|
infos_grille[1] = (this.ValeurEntre/this.Taille);
|
|
infos_grille[2] = (this.ValeurEntre%this.Taille);
|
|
infos_grille[3] = (this.ValeurSortie/this.Taille);
|
|
infos_grille[4] = (this.ValeurSortie%this.Taille);
|
|
return infos_grille;
|
|
}
|
|
|
|
protected JPanel[][] getGrille(){
|
|
return this.TabDePanel;
|
|
}
|
|
}
|