Grosse Update - 20, Apres avoir travaillé sur un autre repertoire git pour ne pas perdre tout mon précédent travail, voici la nouvelle version qui est au même stade
This commit is contained in:
parent
cb05df474c
commit
9f1f7cb7d7
@ -1,24 +0,0 @@
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Random;
|
||||
|
||||
public class ASupprimer {
|
||||
|
||||
public static void main(String[] args) {
|
||||
byte[] bytes = {9, 0, 0, 7, 7};
|
||||
String fileName = "Grand.lab";
|
||||
|
||||
try (FileOutputStream outputStream = new FileOutputStream(fileName)) {
|
||||
outputStream.write(bytes);
|
||||
System.out.println("Les 5 premiers octets ont été écrits avec succès !");
|
||||
|
||||
byte[] randomBytes = new byte[10];
|
||||
new Random().nextBytes(randomBytes);
|
||||
outputStream.write(randomBytes);
|
||||
System.out.println("10 octets aléatoires ont été ajoutés au fichier !");
|
||||
} catch (IOException e) {
|
||||
System.err.println("Erreur lors de la création ou de l'écriture du fichier " + fileName);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
62
Affichage.java
Normal file
62
Affichage.java
Normal file
@ -0,0 +1,62 @@
|
||||
public class Affichage {
|
||||
public static final int COULOIR=0;
|
||||
public static final int MUR=1;
|
||||
public static final int ENTREE=2;
|
||||
public static final int SORTIE=3;
|
||||
|
||||
public static final boolean LIBRE = true;
|
||||
public static final boolean OCCUPE = false;
|
||||
|
||||
private Cellules cetteCellules;
|
||||
private PanneauModification cePanel;
|
||||
|
||||
private boolean cetEtat;
|
||||
|
||||
private int[] caseEntrortie;
|
||||
|
||||
public Affichage(Cellules uneCellules, PanneauModification unPanel, int[] tabEntre, boolean unEtat){
|
||||
this.cetteCellules = uneCellules;
|
||||
this.cePanel = unPanel;
|
||||
this.cetEtat = unEtat;
|
||||
this.caseEntrortie = tabEntre;
|
||||
|
||||
repaint();
|
||||
}
|
||||
|
||||
public int[] getGateState(){
|
||||
return this.caseEntrortie;
|
||||
}
|
||||
|
||||
public void repaint(){
|
||||
// Accéder aux boutons radios de l'objet Options
|
||||
boolean radio1Selected = this.cePanel.GetButtonBW().isSelected(); // MUR / COULOIR
|
||||
boolean radio2Selected = this.cePanel.GetButtonE().isSelected(); // ENTREE
|
||||
boolean radio3Selected = this.cePanel.GetButtonS().isSelected(); //SORTIE
|
||||
|
||||
if(radio2Selected==true && this.caseEntrortie[0]==0){
|
||||
this.caseEntrortie[0]=1;
|
||||
this.cetteCellules.setType(ENTREE);
|
||||
this.cetteCellules.peindre(ENTREE);
|
||||
} else if(radio3Selected==true && this.caseEntrortie[1]==0){
|
||||
this.caseEntrortie[1]=1;
|
||||
this.cetteCellules.setType(SORTIE);
|
||||
this.cetteCellules.peindre(SORTIE);
|
||||
} else if(radio1Selected==true && this.cetEtat==true){
|
||||
if(this.caseEntrortie[0]==1){
|
||||
this.caseEntrortie[0]=0;
|
||||
} else if(this.caseEntrortie[1]==1){
|
||||
this.caseEntrortie[1]=0;
|
||||
}
|
||||
this.cetteCellules.setType(COULOIR);
|
||||
this.cetteCellules.peindre(COULOIR);
|
||||
} else if(radio1Selected==true && this.cetEtat==OCCUPE){
|
||||
if(this.caseEntrortie[0]==1){
|
||||
this.caseEntrortie[0]=0;
|
||||
} else if(this.caseEntrortie[1]==1){
|
||||
this.caseEntrortie[1]=0;
|
||||
}
|
||||
this.cetteCellules.setType(MUR);
|
||||
this.cetteCellules.peindre(MUR);
|
||||
}
|
||||
}
|
||||
}
|
73
Cellules.java
Normal file
73
Cellules.java
Normal file
@ -0,0 +1,73 @@
|
||||
import java.awt.Color;
|
||||
import javax.swing.JComponent;
|
||||
|
||||
import java.awt.Graphics;
|
||||
|
||||
public class Cellules extends JComponent{
|
||||
public static final int COULOIR=0;
|
||||
public static final int MUR=1;
|
||||
public static final int ENTREE=2;
|
||||
public static final int SORTIE=3;
|
||||
|
||||
private Color backgroundColor;
|
||||
|
||||
private int cetteLigne;
|
||||
private int cetteColone;
|
||||
private int ceType;
|
||||
|
||||
public Cellules(int uneLigne, int uneColone, int type){
|
||||
super();
|
||||
this.cetteLigne=uneLigne;
|
||||
this.cetteColone=uneColone;
|
||||
|
||||
this.ceType = type;
|
||||
|
||||
peindre(ceType);
|
||||
}
|
||||
|
||||
public int getLigne(){
|
||||
return this.cetteLigne;
|
||||
}
|
||||
|
||||
public int getColone(){
|
||||
return this.cetteColone;
|
||||
}
|
||||
|
||||
public int getType(){
|
||||
return this.ceType;
|
||||
}
|
||||
|
||||
public void setType(int newType){
|
||||
if(newType==COULOIR){
|
||||
this.ceType = COULOIR;
|
||||
} else if(newType==MUR){
|
||||
this.ceType = MUR;
|
||||
} else if(newType==ENTREE){
|
||||
this.ceType = ENTREE;
|
||||
} else if(newType==SORTIE){
|
||||
this.ceType = SORTIE;
|
||||
}
|
||||
}
|
||||
|
||||
public void peindre(int peinture){
|
||||
if(peinture==COULOIR){
|
||||
backgroundColor = Color.WHITE;
|
||||
} else if(peinture==MUR){
|
||||
backgroundColor = Color.BLACK;
|
||||
} else if(peinture==ENTREE){
|
||||
backgroundColor = Color.BLUE;
|
||||
} else if(peinture==SORTIE){
|
||||
backgroundColor = Color.RED;
|
||||
}
|
||||
|
||||
repaint();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
|
||||
g.setColor(backgroundColor);
|
||||
g.fillRect(0, 0, getWidth(), getHeight());
|
||||
}
|
||||
}
|
@ -19,12 +19,12 @@ public class ChoixEtTaille extends JFrame implements ActionListener {
|
||||
|
||||
if(this.ce_group.getSelection().getActionCommand()=="Grille randomisée"){
|
||||
FenetreRndmGrille cette_fenetre = new FenetreRndmGrille(Integer.parseInt(valleur_taille));
|
||||
cette_fenetre.RandomGrille();
|
||||
cette_fenetre.randomGrille();
|
||||
}
|
||||
|
||||
else if(this.ce_group.getSelection().getActionCommand()=="Grille vide"){
|
||||
FenetreVideGrille cette_fenetre = new FenetreVideGrille(Integer.parseInt(valleur_taille));
|
||||
cette_fenetre.CreerVide();
|
||||
cette_fenetre.videGrille();
|
||||
}
|
||||
}
|
||||
}
|
12
Ecrire.java
12
Ecrire.java
@ -1,12 +0,0 @@
|
||||
import java.io.*;
|
||||
|
||||
public class Ecrire {
|
||||
|
||||
public Ecrire(String filePath, int[] tableau, int[] tableau2){
|
||||
try (BufferedWriter writer = new BufferedWriter(new FileWriter(filePath))) {
|
||||
writer.write("Contenu du fichier");
|
||||
} catch (IOException ex) {
|
||||
System.err.println("Une erreur s'est produite lors de l'écriture dans le fichier : " + ex.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
@ -1,35 +0,0 @@
|
||||
import javax.swing.*;
|
||||
import javax.swing.filechooser.FileNameExtensionFilter;
|
||||
import java.io.*;
|
||||
|
||||
public class Enregistrer {
|
||||
|
||||
public Enregistrer(){
|
||||
|
||||
}
|
||||
|
||||
public File GetPath(){
|
||||
JFileChooser fileChooser = new JFileChooser();
|
||||
fileChooser.setDialogTitle("Save file");
|
||||
|
||||
// Filtre pour n'afficher que les fichiers de type .txt
|
||||
FileNameExtensionFilter filter = new FileNameExtensionFilter("Fichier hexadecimal (*.lab)", "lab");
|
||||
fileChooser.setFileFilter(filter);
|
||||
|
||||
// Afficher la boîte de dialogue "enregistrer sous"
|
||||
int userSelection = fileChooser.showSaveDialog(null);
|
||||
|
||||
if (userSelection == JFileChooser.APPROVE_OPTION) {
|
||||
File fileToSave = fileChooser.getSelectedFile();
|
||||
|
||||
// Ajouter l'extension .txt si elle n'a pas été saisie
|
||||
if (!fileToSave.getAbsolutePath().endsWith(".lab")) {
|
||||
fileToSave = new File(fileToSave.getAbsolutePath() + ".lab");
|
||||
}
|
||||
|
||||
return fileToSave;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class Exporter {
|
||||
private int[] infos_grille;
|
||||
private JPanel[][] composanteGrille;
|
||||
private FenetreRndmGrille cetteFrg;
|
||||
private int Taille;
|
||||
|
||||
public Exporter(FenetreRndmGrille uneFrg){
|
||||
this.cetteFrg = uneFrg;
|
||||
}
|
||||
|
||||
public void jsp(){
|
||||
this.infos_grille=this.cetteFrg.get_info();
|
||||
this.Taille=this.infos_grille[0];
|
||||
this.composanteGrille=this.cetteFrg.getGrille();
|
||||
for(int i=0; i<this.infos_grille.length;i++){
|
||||
System.out.println(i+" elt : "+this.infos_grille[i]);
|
||||
}
|
||||
for(int i=0; i<this.Taille;i++){
|
||||
for(int j=0; j<this.Taille; j++){
|
||||
System.out.println("la couleur que je ne vois pas haha : "+this.composanteGrille[i][j].getBackground());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class ExporterFRG {
|
||||
private int[] infos_grille;
|
||||
private JPanel[][] composanteGrille;
|
||||
private FenetreRndmGrille cetteFrg;
|
||||
private int Taille;
|
||||
|
||||
public ExporterFRG(FenetreRndmGrille uneFrg){
|
||||
this.cetteFrg = uneFrg;
|
||||
}
|
||||
|
||||
public void jsp(){
|
||||
this.infos_grille=this.cetteFrg.get_info();
|
||||
this.Taille=this.infos_grille[0];
|
||||
this.composanteGrille=this.cetteFrg.getGrille();
|
||||
for(int i=0; i<this.infos_grille.length;i++){
|
||||
System.out.println(i+" elt : "+this.infos_grille[i]);
|
||||
}
|
||||
for(int i=0; i<this.Taille;i++){
|
||||
for(int j=0; j<this.Taille; j++){
|
||||
/*System.out.println("la couleur que je ne vois pas haha : "+this.composanteGrille[i][j].getBackground());*/
|
||||
}
|
||||
}
|
||||
Enregistrer dwnld = new Enregistrer();
|
||||
}
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class ExporterFVG {
|
||||
private int[] infos_grille;
|
||||
private JPanel[][] composanteGrille;
|
||||
private FenetreVideGrille cetteFvg;
|
||||
private int Taille;
|
||||
|
||||
public ExporterFVG(FenetreVideGrille uneFvg){
|
||||
this.cetteFvg = uneFvg;
|
||||
}
|
||||
|
||||
public void jsp(){
|
||||
this.infos_grille=this.cetteFvg.get_info();
|
||||
this.Taille=this.infos_grille[0];
|
||||
this.composanteGrille=this.cetteFvg.getGrille();
|
||||
for(int i=0; i<this.Taille;i++){
|
||||
for(int j=0; j<this.Taille; j++){
|
||||
//System.out.println("la couleur que je ne vois pas haha : "+this.composanteGrille[i][j].getBackground());
|
||||
}
|
||||
}
|
||||
Enregistrer dwnld = new Enregistrer();
|
||||
dwnld.GetPath();
|
||||
}
|
||||
}
|
@ -1,64 +1,62 @@
|
||||
import java.awt.*;
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.Border;
|
||||
|
||||
public class FenetreImpGrille extends Fenetre {
|
||||
public static final int COULOIR=0;
|
||||
public static final int MUR=1;
|
||||
public static final int ENTREE=2;
|
||||
public static final int SORTIE=3;
|
||||
|
||||
private boolean[][] grille;
|
||||
|
||||
public FenetreImpGrille(){
|
||||
super();
|
||||
}
|
||||
|
||||
public void ImporterGrille(int Taille, int Lentre, int Centre, int Lortie, int Cortie, int[] un_tab){
|
||||
public void ImporterGrille(int taille, int Lentre, int Centre, int Lortie, int Cortie, int[] un_tab){
|
||||
/* ================================================================ Déclaration des variables ============================================================================= */
|
||||
|
||||
int compteur=0;
|
||||
int[][] ce_double_tab = new int[Taille][Taille];
|
||||
int[][] ce_double_tab = new int[taille][taille];
|
||||
this.grille = new boolean[taille][taille];
|
||||
|
||||
/* =============================================================== Gestion des paramètres de la fenètre ========================================================================== */
|
||||
|
||||
/*Création de la fenètre */
|
||||
this.fenetre.setSize(600, 600);
|
||||
|
||||
/*Mise en place du grid layout */
|
||||
GridLayout gestionnaire = new GridLayout(Taille,Taille);
|
||||
GridLayout gestionnaire = new GridLayout(taille,taille);
|
||||
this.fenetre.setLayout(gestionnaire);
|
||||
|
||||
/* ================================================================================================================================================================ */
|
||||
|
||||
|
||||
/* remplissage du tab 1 */
|
||||
|
||||
for(int i=0; i<Taille; i++){
|
||||
for(int j=0; j<Taille; j++){
|
||||
for(int i=0; i<taille; i++){
|
||||
for(int j=0; j<taille; j++){
|
||||
ce_double_tab[j][i] = un_tab[compteur];
|
||||
compteur++;
|
||||
}
|
||||
}
|
||||
|
||||
/* ======================================================================================================================================= */
|
||||
|
||||
// Gestion du remplissage des case
|
||||
for(int i=0; i<taille; i++){
|
||||
for(int j=0; j<taille; j++){
|
||||
|
||||
for(int i=0; i<Taille; i++){
|
||||
for(int j=0; j<Taille; j++){
|
||||
|
||||
JPanel ce_pannel = new JPanel();
|
||||
|
||||
if((i*Taille+j)==(Lentre*Taille+Centre)){
|
||||
ce_pannel.setBackground(Color.RED);
|
||||
this.fenetre.add(ce_pannel);
|
||||
} else if((i*Taille+j)==(Lortie*Taille+Cortie)){
|
||||
ce_pannel.setBackground(Color.BLUE);
|
||||
this.fenetre.add(ce_pannel);
|
||||
} else if(ce_double_tab[i][j] == 1){
|
||||
ce_pannel.setBackground(Color.BLACK);
|
||||
this.fenetre.add(ce_pannel);
|
||||
if(ce_double_tab[i][j] == 0){
|
||||
this.grille[i][j] = false;
|
||||
} else {
|
||||
JPanel ce_panel = new JPanel();
|
||||
Border border = BorderFactory.createLineBorder(Color.BLACK, 1);
|
||||
ce_panel.setBorder(border);
|
||||
ce_panel.setBackground(Color.WHITE);
|
||||
this.fenetre.add(ce_panel);
|
||||
this.grille[i][j] = true;
|
||||
}
|
||||
|
||||
if((i*taille+j)==(Lentre*taille+Centre)){
|
||||
Cellules cellules = new Cellules(i, j, ENTREE);
|
||||
this.fenetre.add(cellules);
|
||||
} else if((i*taille+j)==(Lortie*taille+Cortie)){
|
||||
Cellules cellules = new Cellules(i, j, SORTIE);
|
||||
this.fenetre.add(cellules);
|
||||
} else if(ce_double_tab[i][j] == 1){
|
||||
Cellules cellules = new Cellules(i, j, MUR);
|
||||
this.fenetre.add(cellules);
|
||||
} else{
|
||||
Cellules cellules = new Cellules(i, j, COULOIR);
|
||||
this.fenetre.add(cellules);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -40,10 +40,10 @@ public class FenetreInit extends Fenetre
|
||||
|
||||
/*Gestion des événements */
|
||||
|
||||
creer salut = new creer(fenetre);
|
||||
Creer salut = new Creer(fenetre);
|
||||
un_Button0.addActionListener(salut);
|
||||
|
||||
importer bImporter = new importer(this.fenetre);
|
||||
Importer bImporter = new Importer(this.fenetre);
|
||||
un_Button1.addActionListener(bImporter);
|
||||
|
||||
/*Ajouts des elts à la fenètre */
|
||||
|
@ -1,116 +1,98 @@
|
||||
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;
|
||||
public static final int COULOIR=0;
|
||||
public static final int MUR=1;
|
||||
public static final int ENTREE=2;
|
||||
public static final int SORTIE=3;
|
||||
|
||||
public static final int RANDOM=1;
|
||||
|
||||
private int taille;
|
||||
private int ValeurEntre;
|
||||
private int ValeurSortie;
|
||||
|
||||
private JPanel[][] TabDePanel;
|
||||
private int[] tabCouleur;
|
||||
private boolean[][] grille;
|
||||
|
||||
public FenetreRndmGrille(int Taille){
|
||||
public FenetreRndmGrille(int taille){
|
||||
super();
|
||||
this.tab_de_int = new int[] {1, 1};
|
||||
this.Taille = Taille;
|
||||
this.TabDePanel = new JPanel[this.Taille][this.Taille];
|
||||
this.taille = taille;
|
||||
this.grille = new boolean[this.taille][this.taille];
|
||||
this.tabCouleur = new int[] {1, 1};
|
||||
}
|
||||
|
||||
public void RandomGrille(){
|
||||
public void randomGrille(){
|
||||
|
||||
this.fenetre.setSize(600, 600);
|
||||
this.fenetre.setLocation(450, 200);
|
||||
|
||||
GridLayout gestionnaire = new GridLayout(this.Taille,this.Taille);
|
||||
GridLayout gestionnaire = new GridLayout(this.taille,this.taille);
|
||||
this.fenetre.setLayout(gestionnaire);
|
||||
|
||||
OptionsFRG un_Test = new OptionsFRG(this);
|
||||
un_Test.SetUp();
|
||||
PanneauModification interfacePanel = new PanneauModification(this.grille, this.taille);
|
||||
interfacePanel.SetUp();
|
||||
|
||||
/* ======= Valeurs aléatoire pour l'entre et la sortie ========== */
|
||||
|
||||
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);
|
||||
ValeurEntre = rand.nextInt(this.taille*this.taille);
|
||||
ValeurSortie = rand.nextInt(this.taille*this.taille);
|
||||
|
||||
if(ValeurEntre == ValeurSortie){
|
||||
while(ValeurEntre == ValeurSortie){
|
||||
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();
|
||||
for(int i=0; i<taille; i++){
|
||||
for(int j=0; j<taille; j++){
|
||||
int nombreAleatoire = rand.nextInt(2); // génère un nombre entre 0 et 2
|
||||
|
||||
if(nombreAleatoire == 0){
|
||||
grille[i][j] = false;
|
||||
} 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();
|
||||
grille[i][j] = true;
|
||||
}
|
||||
|
||||
Modifications modif = new Modifications(interfacePanel, grille,this.tabCouleur);
|
||||
|
||||
if(compteur == ValeurEntre)
|
||||
{
|
||||
Cellules cellules = new Cellules(i,j, ENTREE);
|
||||
this.fenetre.add(cellules);
|
||||
cellules.addMouseListener(modif);
|
||||
}
|
||||
else if(compteur == ValeurSortie)
|
||||
{
|
||||
Cellules cellules = new Cellules(i, j, SORTIE);
|
||||
this.fenetre.add(cellules);
|
||||
cellules.addMouseListener(modif);
|
||||
}
|
||||
else if(grille[i][j] == true)
|
||||
{
|
||||
Cellules cellules = new Cellules(i, j, COULOIR);
|
||||
this.fenetre.add(cellules);
|
||||
cellules.addMouseListener(modif);
|
||||
}
|
||||
else
|
||||
{
|
||||
Cellules cellules = new Cellules(i, j, MUR);
|
||||
this.fenetre.add(cellules);
|
||||
cellules.addMouseListener(modif);
|
||||
}
|
||||
|
||||
this.tabCouleur = modif.getGateState();
|
||||
compteur++;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/*System.out.print("\n");
|
||||
PrintGrille afficGrille = new PrintGrille(grille, taille);*/
|
||||
this.fenetre.setVisible(true);
|
||||
}
|
||||
|
||||
public 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;
|
||||
}
|
||||
|
||||
public JPanel[][] getGrille(){
|
||||
return this.TabDePanel;
|
||||
}
|
||||
}
|
||||
|
@ -1,62 +1,53 @@
|
||||
import java.awt.*;
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.Border;
|
||||
|
||||
public class FenetreVideGrille extends Fenetre{
|
||||
private int[] tab_de_int;
|
||||
private int Taille;
|
||||
private int ValeurEntre;
|
||||
private int ValeurSortie;
|
||||
public static final int COULOIR=0;
|
||||
public static final int MUR=1;
|
||||
public static final int ENTREE=2;
|
||||
public static final int SORTIE=3;
|
||||
|
||||
private JPanel[][] TabDePanel;
|
||||
private int taille;
|
||||
|
||||
public FenetreVideGrille(int Taille){
|
||||
private boolean[][] grille;
|
||||
private int[] tabCouleur;
|
||||
|
||||
public FenetreVideGrille(int taille){
|
||||
super();
|
||||
this.tab_de_int = new int[] {0, 0};
|
||||
this.Taille = Taille;
|
||||
this.TabDePanel = new JPanel[this.Taille][this.Taille];
|
||||
this.taille = taille;
|
||||
this.grille = new boolean[this.taille][this.taille];
|
||||
this.tabCouleur = new int[] {0, 0};
|
||||
}
|
||||
|
||||
public void CreerVide(){
|
||||
public void videGrille(){
|
||||
|
||||
this.fenetre.setSize(600, 600);
|
||||
this.fenetre.setLocation(450, 200);
|
||||
|
||||
OptionsFVG un_Test = new OptionsFVG(this);
|
||||
un_Test.SetUp();
|
||||
|
||||
GridLayout gestionnaire = new GridLayout(Taille,Taille);
|
||||
GridLayout gestionnaire = new GridLayout(this.taille,this.taille);
|
||||
this.fenetre.setLayout(gestionnaire);
|
||||
|
||||
for(int i=0; i<this.Taille; i++){
|
||||
for(int j=0; j<this.Taille; j++){
|
||||
PanneauModification interfacePanel = new PanneauModification(this.grille, this.taille);
|
||||
interfacePanel.SetUp();
|
||||
|
||||
JPanel ce_panel = new JPanel();
|
||||
this.TabDePanel[j][i] = ce_panel;
|
||||
/* =============================================================== */
|
||||
|
||||
Border border = BorderFactory.createLineBorder(Color.BLACK, 1);
|
||||
ce_panel.setBorder(border);
|
||||
ce_panel.setBackground(Color.WHITE);
|
||||
this.fenetre.add(ce_panel);
|
||||
|
||||
ModificationsFVG testee = new ModificationsFVG(un_Test, this.tab_de_int);
|
||||
ce_panel.addMouseListener(testee);
|
||||
this.tab_de_int=testee.getValues();
|
||||
/* =============================================================== */
|
||||
|
||||
|
||||
for(int i=0; i<taille; i++){
|
||||
for(int j=0; j<taille; j++){
|
||||
Modifications modif = new Modifications(interfacePanel, this.grille, this.tabCouleur);
|
||||
|
||||
grille[i][j] = true;
|
||||
Cellules cellules = new Cellules(i, j, COULOIR);
|
||||
this.fenetre.add(cellules);
|
||||
cellules.addMouseListener(modif);
|
||||
|
||||
this.tabCouleur = modif.getGateState();
|
||||
}
|
||||
}
|
||||
|
||||
this.fenetre.setVisible(true);
|
||||
}
|
||||
|
||||
public 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;
|
||||
}
|
||||
|
||||
public JPanel[][] getGrille(){
|
||||
return this.TabDePanel;
|
||||
}
|
||||
}
|
||||
|
24
GestionModif.java
Normal file
24
GestionModif.java
Normal file
@ -0,0 +1,24 @@
|
||||
import java.awt.event.*;
|
||||
public class GestionModif implements ActionListener{
|
||||
private String Reponses1="Quitter", Reponses2="Sauvegarder";
|
||||
private String cet_event;
|
||||
private boolean[][] cetteGrille;
|
||||
private int cetteTaille;
|
||||
private PrintGrille affiche;
|
||||
|
||||
public GestionModif(boolean[][] uneGrille, int uneTaille){
|
||||
this.cetteGrille=uneGrille;
|
||||
this.cetteTaille=uneTaille;
|
||||
this.affiche = new PrintGrille(this.cetteGrille, this.cetteTaille);
|
||||
}
|
||||
|
||||
public void actionPerformed(ActionEvent e){
|
||||
this.cet_event=e.getActionCommand();
|
||||
if (cet_event.equals(this.Reponses1)){
|
||||
System.exit(1);
|
||||
}
|
||||
else if (cet_event.equals(this.Reponses2)){
|
||||
this.affiche = new PrintGrille(this.cetteGrille, this.cetteTaille);
|
||||
}
|
||||
}
|
||||
}
|
34
Modifications.java
Normal file
34
Modifications.java
Normal file
@ -0,0 +1,34 @@
|
||||
import java.awt.event.*;
|
||||
|
||||
public class Modifications implements MouseListener {
|
||||
private PanneauModification unPanel;
|
||||
private boolean[][] cetteGrille;
|
||||
private int[] ceTab;
|
||||
|
||||
private ModificationsTab change;
|
||||
|
||||
public Modifications(PanneauModification panneauModification, boolean[][] grilleTab, int[] unTab){
|
||||
this.unPanel = panneauModification;
|
||||
this.cetteGrille = grilleTab;
|
||||
this.ceTab = unTab;
|
||||
}
|
||||
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
this.change = new ModificationsTab(this.unPanel, this.cetteGrille, this.ceTab, e);
|
||||
}
|
||||
|
||||
public int[] getGateState(){
|
||||
System.out.println("this.ceTab vaut : [0] : "+this.ceTab[0] + " et this.ceTab vaut : [1] :"+this.ceTab[1]);
|
||||
return this.ceTab;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Les méthodes suivantes ne sont pas utilisées dans cet exemple, donc nous les laissons vides
|
||||
public void mouseExited(MouseEvent e) {}
|
||||
public void mouseReleased(MouseEvent e) {}
|
||||
public void mousePressed(MouseEvent e) {}
|
||||
public void mouseEntered(MouseEvent e) {}
|
||||
|
||||
}
|
||||
|
@ -1,59 +0,0 @@
|
||||
import java.awt.event.*;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class ModificationsFRG implements MouseListener {
|
||||
private int[] ce_tableau ;
|
||||
private OptionsFRG options;
|
||||
|
||||
public ModificationsFRG(OptionsFRG options, int[] un_tab){
|
||||
this.options = options;
|
||||
this.ce_tableau = un_tab;
|
||||
}
|
||||
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
JPanel notre_Panel = (JPanel) e.getSource();
|
||||
|
||||
Color test = notre_Panel.getBackground();
|
||||
|
||||
// Accéder aux boutons radios de l'objet Options
|
||||
boolean radio1Selected = options.GetButtonBW().isSelected();
|
||||
boolean radio2Selected = options.GetButtonE().isSelected();
|
||||
boolean radio3Selected = options.GetButtonS().isSelected();
|
||||
|
||||
if(test==Color.WHITE && radio1Selected==true){
|
||||
notre_Panel.setBackground(Color.BLACK);
|
||||
} else if(test==Color.BLACK && radio1Selected==true){
|
||||
notre_Panel.setBackground(Color.WHITE);
|
||||
}else if(radio1Selected==true && (test==Color.RED || test==Color.BLUE)){
|
||||
if(test==Color.BLUE){
|
||||
notre_Panel.setBackground(Color.WHITE);
|
||||
this.ce_tableau[0] = 0;
|
||||
} else if(test==Color.RED){
|
||||
notre_Panel.setBackground(Color.WHITE);
|
||||
this.ce_tableau[1] = 0;
|
||||
}
|
||||
} else if(test!=Color.BLUE && radio2Selected==true && this.ce_tableau[0]==0){
|
||||
notre_Panel.setBackground(Color.BLUE);
|
||||
this.ce_tableau[0]=1;
|
||||
} else if(test!=Color.RED && radio3Selected==true && this.ce_tableau[1]==0){
|
||||
this.ce_tableau[1]=1;
|
||||
notre_Panel.setBackground(Color.RED);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public int[] getValues(){
|
||||
return this.ce_tableau;
|
||||
}
|
||||
|
||||
public void mouseExited(MouseEvent e) {
|
||||
// Laisser cette méthode vide si vous n'avez pas besoin de l'utiliser
|
||||
}
|
||||
|
||||
// Les méthodes suivantes ne sont pas utilisées dans cet exemple, donc nous les laissons vides
|
||||
public void mouseReleased(MouseEvent e) {}
|
||||
public void mousePressed(MouseEvent e) {}
|
||||
public void mouseEntered(MouseEvent e) {}
|
||||
}
|
@ -1,59 +0,0 @@
|
||||
import java.awt.event.*;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class ModificationsFVG implements MouseListener {
|
||||
private int[] ce_tableau ;
|
||||
private OptionsFVG options;
|
||||
|
||||
public ModificationsFVG(OptionsFVG options, int[] un_tab){
|
||||
this.options = options;
|
||||
this.ce_tableau = un_tab;
|
||||
}
|
||||
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
JPanel notre_Panel = (JPanel) e.getSource();
|
||||
|
||||
Color test = notre_Panel.getBackground();
|
||||
|
||||
// Accéder aux boutons radios de l'objet Options
|
||||
boolean radio1Selected = options.GetButtonBW().isSelected();
|
||||
boolean radio2Selected = options.GetButtonE().isSelected();
|
||||
boolean radio3Selected = options.GetButtonS().isSelected();
|
||||
|
||||
if(test==Color.WHITE && radio1Selected==true){
|
||||
notre_Panel.setBackground(Color.BLACK);
|
||||
} else if(test==Color.BLACK && radio1Selected==true){
|
||||
notre_Panel.setBackground(Color.WHITE);
|
||||
}else if(radio1Selected==true && (test==Color.RED || test==Color.BLUE)){
|
||||
if(test==Color.BLUE){
|
||||
notre_Panel.setBackground(Color.WHITE);
|
||||
this.ce_tableau[0] = 0;
|
||||
} else if(test==Color.RED){
|
||||
notre_Panel.setBackground(Color.WHITE);
|
||||
this.ce_tableau[1] = 0;
|
||||
}
|
||||
} else if(test!=Color.BLUE && radio2Selected==true && this.ce_tableau[0]==0){
|
||||
notre_Panel.setBackground(Color.BLUE);
|
||||
this.ce_tableau[0]=1;
|
||||
} else if(test!=Color.RED && radio3Selected==true && this.ce_tableau[1]==0){
|
||||
this.ce_tableau[1]=1;
|
||||
notre_Panel.setBackground(Color.RED);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public int[] getValues(){
|
||||
return this.ce_tableau;
|
||||
}
|
||||
|
||||
public void mouseExited(MouseEvent e) {
|
||||
// Laisser cette méthode vide si vous n'avez pas besoin de l'utiliser
|
||||
}
|
||||
|
||||
// Les méthodes suivantes ne sont pas utilisées dans cet exemple, donc nous les laissons vides
|
||||
public void mouseReleased(MouseEvent e) {}
|
||||
public void mousePressed(MouseEvent e) {}
|
||||
public void mouseEntered(MouseEvent e) {}
|
||||
}
|
57
ModificationsTab.java
Normal file
57
ModificationsTab.java
Normal file
@ -0,0 +1,57 @@
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
public class ModificationsTab {
|
||||
// --------------------------------------------
|
||||
public static final boolean LIBRE = true;
|
||||
public static final boolean OCCUPE = false;
|
||||
|
||||
public static final int COULOIR=0;
|
||||
public static final int MUR=1;
|
||||
public static final int ENTREE=2;
|
||||
public static final int SORTIE=3;
|
||||
|
||||
// --------------------------------------------
|
||||
|
||||
private boolean[][] cetteGrille;
|
||||
private MouseEvent cetEvent;
|
||||
private int[] tabEtat;
|
||||
|
||||
private int cetteLigne;
|
||||
private int cetteColone;
|
||||
private Affichage rafraichir;
|
||||
private PanneauModification cePanel;
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
public ModificationsTab(PanneauModification panneauModification, boolean[][] grilleTab, int[] unTab, MouseEvent unEvent){
|
||||
this.cetteGrille = grilleTab;
|
||||
this.cetEvent = unEvent;
|
||||
|
||||
this.cePanel = panneauModification;
|
||||
|
||||
Cellules notreCellule = (Cellules) cetEvent.getSource();
|
||||
this.cetteLigne = notreCellule.getLigne();
|
||||
this.cetteColone = notreCellule.getColone();
|
||||
|
||||
this.tabEtat = unTab;
|
||||
|
||||
/* ========================================= */
|
||||
boolean radio1Selected = this.cePanel.GetButtonBW().isSelected(); // MUR / COULOIR
|
||||
boolean radio2Selected = this.cePanel.GetButtonE().isSelected(); // ENTREE
|
||||
boolean radio3Selected = this.cePanel.GetButtonS().isSelected(); //SORTIE
|
||||
/* ========================================= */
|
||||
|
||||
if(this.cetteGrille[this.cetteLigne][this.cetteColone] == LIBRE && radio2Selected==false && radio3Selected==false ){
|
||||
this.cetteGrille[this.cetteLigne][this.cetteColone] = OCCUPE;
|
||||
} else if(this.cetteGrille[this.cetteLigne][this.cetteColone] == OCCUPE){
|
||||
this.cetteGrille[this.cetteLigne][this.cetteColone] = LIBRE;
|
||||
}
|
||||
|
||||
this.rafraichir = new Affichage(notreCellule, panneauModification, unTab, this.cetteGrille[this.cetteLigne][this.cetteColone]);
|
||||
}
|
||||
|
||||
public int[] getGateState(){
|
||||
this.tabEtat = this.rafraichir.getGateState();
|
||||
return this.tabEtat;
|
||||
}
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
import java.awt.event.*;
|
||||
|
||||
public class OptionsBoutonsFRG implements ActionListener{
|
||||
private String Reponses1="Quitter", Reponses2="Sauvegarder";
|
||||
private String cet_event;
|
||||
private ExporterFRG test;
|
||||
private FenetreRndmGrille ce_frg;
|
||||
|
||||
public OptionsBoutonsFRG(FenetreRndmGrille un_frg){
|
||||
this.ce_frg = un_frg;
|
||||
}
|
||||
|
||||
public void actionPerformed(ActionEvent e){
|
||||
this.cet_event=e.getActionCommand();
|
||||
if (cet_event.equals(this.Reponses1)){
|
||||
System.exit(1);
|
||||
}
|
||||
else if (cet_event.equals(this.Reponses2)){
|
||||
System.out.println("Test1");
|
||||
this.test = new ExporterFRG(this.ce_frg);
|
||||
this.test.jsp();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
import java.awt.event.*;
|
||||
|
||||
public class OptionsBoutonsFVG implements ActionListener{
|
||||
private String Reponses1="Quitter", Reponses2="Sauvegarder";
|
||||
private String cet_event;
|
||||
private ExporterFVG test;
|
||||
private FenetreVideGrille ce_fvg;
|
||||
|
||||
public OptionsBoutonsFVG(FenetreVideGrille un_fvg){
|
||||
this.ce_fvg = un_fvg;
|
||||
}
|
||||
|
||||
public void actionPerformed(ActionEvent e){
|
||||
this.cet_event=e.getActionCommand();
|
||||
if (cet_event.equals(this.Reponses1)){
|
||||
System.exit(1);
|
||||
} else if (cet_event.equals(this.Reponses2)){
|
||||
System.out.println("Test1");
|
||||
this.test = new ExporterFVG(this.ce_fvg);
|
||||
this.test.jsp();
|
||||
}
|
||||
}
|
||||
}
|
130
OptionsFVG.java
130
OptionsFVG.java
@ -1,130 +0,0 @@
|
||||
import java.awt.*;
|
||||
import javax.swing.*;
|
||||
|
||||
public class OptionsFVG extends Fenetre {
|
||||
public JRadioButton radio1;
|
||||
public JRadioButton radio2;
|
||||
public JRadioButton radio3;
|
||||
private FenetreVideGrille ce_fvg;
|
||||
|
||||
public OptionsFVG(FenetreVideGrille un_fvg) {
|
||||
super();
|
||||
this.fenetre.setSize(400, 600);
|
||||
this.fenetre.setLocation(1100, 200);
|
||||
this.ce_fvg=un_fvg;
|
||||
}
|
||||
|
||||
public void SetUp(){
|
||||
GridLayout gestionnaire = new GridLayout(4,1);
|
||||
this.fenetre.setLayout(gestionnaire);
|
||||
|
||||
/* Création du premier panneau */
|
||||
|
||||
JLabel un_d_text = new JLabel(" Etape 1 : création du labyrinthe");
|
||||
|
||||
JPanel un_Panel = new JPanel();
|
||||
un_Panel.setBackground(Color.CYAN);
|
||||
|
||||
un_Panel.add(un_d_text, BorderLayout.CENTER);
|
||||
|
||||
JPanel un_Panel2 = new JPanel();
|
||||
un_Panel2.setBackground(Color.CYAN);
|
||||
un_Panel2.setLayout(new BoxLayout(un_Panel2, BoxLayout.Y_AXIS));
|
||||
un_Panel2.add(Box.createVerticalGlue());
|
||||
un_Panel2.add(un_Panel);
|
||||
un_Panel2.add(Box.createVerticalGlue());
|
||||
|
||||
this.fenetre.add(un_Panel2, BorderLayout.CENTER);
|
||||
|
||||
/*Création du deuxième panneau */
|
||||
|
||||
JPanel un_Panel3 = new JPanel();
|
||||
JButton un_Button1 = new JButton("Sauvegarder");
|
||||
|
||||
JPanel un_Panel4 = new JPanel();
|
||||
un_Panel4.add(un_Button1);
|
||||
|
||||
un_Panel3.setBackground(Color.CYAN);
|
||||
un_Panel4.setBackground(Color.CYAN);
|
||||
|
||||
un_Panel3.setBackground(Color.CYAN);
|
||||
un_Panel3.setLayout(new BoxLayout(un_Panel3, BoxLayout.Y_AXIS));
|
||||
un_Panel3.add(Box.createVerticalGlue());
|
||||
un_Panel3.add(un_Panel4);
|
||||
un_Panel3.add(Box.createVerticalGlue());
|
||||
|
||||
this.fenetre.add(un_Panel3, BorderLayout.CENTER);
|
||||
|
||||
/* Nouveau panneau grille choix */
|
||||
|
||||
JPanel un_Panel10 = new JPanel();
|
||||
JPanel un_Panel11 = new JPanel();
|
||||
|
||||
radio1 = new JRadioButton("Construire ou Effacer");
|
||||
radio2 = new JRadioButton("Entrée");
|
||||
radio3 = new JRadioButton("Sortie");
|
||||
|
||||
radio1.setBackground(Color.CYAN);
|
||||
radio2.setBackground(Color.CYAN);
|
||||
radio3.setBackground(Color.CYAN);
|
||||
|
||||
radio1.setSelected(true);
|
||||
|
||||
ButtonGroup group = new ButtonGroup();
|
||||
group.add(radio1);group.add(radio2); group.add(radio3);
|
||||
|
||||
un_Panel11.add(radio1);
|
||||
un_Panel11.add(radio2);
|
||||
un_Panel11.add(radio3);
|
||||
|
||||
un_Panel10.setBackground(Color.CYAN);
|
||||
un_Panel10.setLayout(new BoxLayout(un_Panel10, BoxLayout.Y_AXIS));
|
||||
un_Panel10.add(Box.createVerticalGlue());
|
||||
un_Panel10.add(un_Panel11);
|
||||
un_Panel10.add(Box.createVerticalGlue());
|
||||
|
||||
|
||||
un_Panel10.setBackground(Color.CYAN);
|
||||
un_Panel11.setBackground(Color.CYAN);
|
||||
this.fenetre.add(un_Panel10, BorderLayout.CENTER);
|
||||
|
||||
/*Création du deuxième panneau */
|
||||
|
||||
JPanel un_Panel5 = new JPanel();
|
||||
JButton un_Button2 = new JButton("Quitter");
|
||||
|
||||
JPanel un_Panel6 = new JPanel();
|
||||
un_Panel6.add(un_Button2, BorderLayout.CENTER);
|
||||
|
||||
un_Panel5.setBackground(Color.CYAN);
|
||||
un_Panel6.setBackground(Color.CYAN);
|
||||
|
||||
un_Panel5.setBackground(Color.CYAN);
|
||||
un_Panel5.setLayout(new BoxLayout(un_Panel5, BoxLayout.Y_AXIS));
|
||||
un_Panel5.add(Box.createVerticalGlue());
|
||||
un_Panel5.add(un_Panel6);
|
||||
un_Panel5.add(Box.createVerticalGlue());
|
||||
|
||||
this.fenetre.add(un_Panel5, BorderLayout.CENTER);
|
||||
|
||||
/* */
|
||||
|
||||
OptionsBoutonsFVG ces_options = new OptionsBoutonsFVG(this.ce_fvg);
|
||||
un_Button1.addActionListener(ces_options);
|
||||
un_Button2.addActionListener(ces_options);
|
||||
|
||||
/* Evenement */
|
||||
|
||||
this.fenetre.setVisible(true);
|
||||
}
|
||||
|
||||
public JRadioButton GetButtonBW() {
|
||||
return radio1;
|
||||
}
|
||||
public JRadioButton GetButtonE() {
|
||||
return radio2;
|
||||
}
|
||||
public JRadioButton GetButtonS() {
|
||||
return radio3;
|
||||
}
|
||||
}
|
@ -1,17 +1,19 @@
|
||||
import java.awt.*;
|
||||
import javax.swing.*;
|
||||
|
||||
public class OptionsFRG extends Fenetre {
|
||||
public class PanneauModification extends Fenetre {
|
||||
public JRadioButton radio1;
|
||||
public JRadioButton radio2;
|
||||
public JRadioButton radio3;
|
||||
private FenetreRndmGrille ce_frg;
|
||||
|
||||
public OptionsFRG(FenetreRndmGrille un_frg){
|
||||
private boolean[][] cetteGrille;
|
||||
private int cetteTaille;
|
||||
|
||||
public PanneauModification(boolean[][] uneGrille, int uneTaille){
|
||||
super();
|
||||
this.fenetre.setSize(400, 600);
|
||||
this.fenetre.setLocation(1100, 200);
|
||||
this.ce_frg = un_frg;
|
||||
this.cetteGrille=uneGrille;
|
||||
this.cetteTaille=uneTaille;
|
||||
}
|
||||
|
||||
public void SetUp(){
|
||||
@ -19,101 +21,74 @@ public class OptionsFRG extends Fenetre {
|
||||
this.fenetre.setLayout(gestionnaire);
|
||||
|
||||
/* Création du premier panneau */
|
||||
|
||||
JLabel un_d_text = new JLabel(" Etape 1 : création du labyrinthe");
|
||||
|
||||
JPanel un_Panel = new JPanel();
|
||||
un_Panel.setBackground(Color.CYAN);
|
||||
|
||||
un_Panel.add(un_d_text, BorderLayout.CENTER);
|
||||
|
||||
JPanel un_Panel2 = new JPanel();
|
||||
un_Panel2.setBackground(Color.CYAN);
|
||||
un_Panel2.setLayout(new BoxLayout(un_Panel2, BoxLayout.Y_AXIS));
|
||||
un_Panel2.add(Box.createVerticalGlue());
|
||||
un_Panel2.add(un_Panel);
|
||||
un_Panel2.add(Box.createVerticalGlue());
|
||||
|
||||
this.fenetre.add(un_Panel2, BorderLayout.CENTER);
|
||||
|
||||
/*Création du deuxième panneau */
|
||||
|
||||
JPanel un_Panel3 = new JPanel();
|
||||
JButton un_Button1 = new JButton("Sauvegarder");
|
||||
|
||||
JPanel un_Panel4 = new JPanel();
|
||||
un_Panel4.add(un_Button1);
|
||||
|
||||
un_Panel3.setBackground(Color.CYAN);
|
||||
un_Panel4.setBackground(Color.CYAN);
|
||||
|
||||
un_Panel3.setBackground(Color.CYAN);
|
||||
un_Panel3.setLayout(new BoxLayout(un_Panel3, BoxLayout.Y_AXIS));
|
||||
un_Panel3.add(Box.createVerticalGlue());
|
||||
un_Panel3.add(un_Panel4);
|
||||
un_Panel3.add(Box.createVerticalGlue());
|
||||
|
||||
this.fenetre.add(un_Panel3, BorderLayout.CENTER);
|
||||
|
||||
/* Nouveau panneau grille choix */
|
||||
|
||||
/*============================ Nouveau panneau grille choix ============================*/
|
||||
JPanel un_Panel10 = new JPanel();
|
||||
JPanel un_Panel11 = new JPanel();
|
||||
|
||||
radio1 = new JRadioButton("Construire ou Effacer");
|
||||
radio2 = new JRadioButton("Entrée");
|
||||
radio3 = new JRadioButton("Sortie");
|
||||
|
||||
radio1.setBackground(Color.CYAN);
|
||||
radio2.setBackground(Color.CYAN);
|
||||
radio3.setBackground(Color.CYAN);
|
||||
|
||||
radio1.setSelected(true);
|
||||
|
||||
ButtonGroup group = new ButtonGroup();
|
||||
group.add(radio1);group.add(radio2); group.add(radio3);
|
||||
|
||||
un_Panel11.add(radio1);
|
||||
un_Panel11.add(radio2);
|
||||
un_Panel11.add(radio3);
|
||||
|
||||
un_Panel10.setBackground(Color.CYAN);
|
||||
un_Panel10.setLayout(new BoxLayout(un_Panel10, BoxLayout.Y_AXIS));
|
||||
un_Panel10.add(Box.createVerticalGlue());
|
||||
un_Panel10.add(un_Panel11);
|
||||
un_Panel10.add(Box.createVerticalGlue());
|
||||
|
||||
|
||||
un_Panel10.setBackground(Color.CYAN);
|
||||
un_Panel11.setBackground(Color.CYAN);
|
||||
this.fenetre.add(un_Panel10, BorderLayout.CENTER);
|
||||
|
||||
/*Création du deuxième panneau */
|
||||
|
||||
JPanel un_Panel5 = new JPanel();
|
||||
JButton un_Button2 = new JButton("Quitter");
|
||||
|
||||
JPanel un_Panel6 = new JPanel();
|
||||
un_Panel6.add(un_Button2, BorderLayout.CENTER);
|
||||
|
||||
un_Panel5.setBackground(Color.CYAN);
|
||||
un_Panel6.setBackground(Color.CYAN);
|
||||
|
||||
un_Panel5.setBackground(Color.CYAN);
|
||||
un_Panel5.setLayout(new BoxLayout(un_Panel5, BoxLayout.Y_AXIS));
|
||||
un_Panel5.add(Box.createVerticalGlue());
|
||||
un_Panel5.add(un_Panel6);
|
||||
un_Panel5.add(Box.createVerticalGlue());
|
||||
|
||||
this.fenetre.add(un_Panel5, BorderLayout.CENTER);
|
||||
|
||||
/* */
|
||||
|
||||
OptionsBoutonsFRG ces_options = new OptionsBoutonsFRG(this.ce_frg);
|
||||
un_Button1.addActionListener(ces_options);
|
||||
un_Button2.addActionListener(ces_options);
|
||||
|
||||
/* Evenement */
|
||||
GestionModif cesOptions = new GestionModif(this.cetteGrille, this.cetteTaille);
|
||||
un_Button1.addActionListener(cesOptions);
|
||||
un_Button2.addActionListener(cesOptions);
|
||||
|
||||
this.fenetre.setVisible(true);
|
||||
}
|
11
PrintGrille.java
Normal file
11
PrintGrille.java
Normal file
@ -0,0 +1,11 @@
|
||||
public class PrintGrille {
|
||||
public PrintGrille(boolean[][] tab, int taille){
|
||||
for(int i=0; i<taille; i++){
|
||||
for(int j=0; j<taille; j++){
|
||||
System.out.print(tab[i][j]+" ");
|
||||
}
|
||||
System.out.print("\n");
|
||||
}
|
||||
System.out.print("\n ------------ \n FIN \n");
|
||||
}
|
||||
}
|
118
SAVE.txt
Normal file
118
SAVE.txt
Normal file
@ -0,0 +1,118 @@
|
||||
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 int[][] grille;
|
||||
|
||||
public FenetreRndmGrille(int taille){
|
||||
super();
|
||||
this.tab_de_int = new int[] {1, 1};
|
||||
this.taille = taille;
|
||||
this.grille = new int[this.taille][this.taille];
|
||||
}
|
||||
|
||||
public 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();
|
||||
|
||||
/* ======= Valeurs aléatoire pour l'entre et la sortie ========== */
|
||||
|
||||
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
|
||||
|
||||
Cellules cellules = new Cellules(i, j);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
public 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;
|
||||
}
|
||||
|
||||
public JPanel[][] getGrille(){
|
||||
return this.TabDePanel;
|
||||
}
|
||||
}
|
82
TEMP.txt
Normal file
82
TEMP.txt
Normal file
@ -0,0 +1,82 @@
|
||||
|
||||
import java.awt.event.*;
|
||||
|
||||
public class Modifications implements MouseListener {
|
||||
// Def Constante
|
||||
public static final int COULOIR=0;
|
||||
public static final int MUR=1;
|
||||
public static final int ENTREE=2;
|
||||
public static final int SORTIE=3;
|
||||
|
||||
public static final boolean OCCUPE = false;
|
||||
public static final boolean LIBRE = true;
|
||||
|
||||
// Def variable
|
||||
|
||||
private boolean[][] grilleTab ;
|
||||
private int[] ceTab ;
|
||||
private PanneauModification options;
|
||||
|
||||
private int cetteLigne = 0;
|
||||
private int cetteColone = 0;
|
||||
private int ceType = 0;
|
||||
|
||||
private int grilleType;
|
||||
|
||||
private int cellulesBleu = 0;
|
||||
private int cellulesRouge = 0;
|
||||
|
||||
public Modifications(PanneauModification panneauModification, boolean[][] grilleTab, int[] unTab){
|
||||
this.options = panneauModification;
|
||||
this.grilleTab = grilleTab;
|
||||
this.ceTab = unTab;
|
||||
}
|
||||
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
Cellules notreCellule = (Cellules) e.getSource();
|
||||
|
||||
this.cetteLigne = notreCellule.getLigne();
|
||||
this.cetteColone = notreCellule.getColone();
|
||||
this.ceType = notreCellule.getType();
|
||||
|
||||
// Accéder aux boutons radios de l'objet Options
|
||||
boolean radio1Selected = options.GetButtonBW().isSelected(); // MUR / COULOIR
|
||||
boolean radio2Selected = options.GetButtonE().isSelected(); // ENTREE
|
||||
boolean radio3Selected = options.GetButtonS().isSelected(); //SORTIE
|
||||
|
||||
if(this.grilleTab[this.cetteLigne][this.cetteColone] == false && this.ceType==MUR && radio1Selected==true){
|
||||
this.grilleTab[this.cetteLigne][this.cetteColone] = LIBRE;
|
||||
notreCellule.setType(COULOIR);
|
||||
System.out.println("voici le type de la case : "+ notreCellule.getType());
|
||||
} else if(this.grilleTab[this.cetteLigne][this.cetteColone] == true && this.ceType==COULOIR && radio1Selected==true){
|
||||
this.grilleTab[this.cetteLigne][this.cetteColone] = OCCUPE;
|
||||
notreCellule.setType(MUR);
|
||||
} else if(radio2Selected==true && this.ceTab[0] == 0){
|
||||
this.grilleTab[this.cetteLigne][this.cetteColone] = LIBRE;
|
||||
notreCellule.setType(ENTREE);
|
||||
this.ceTab[0] = 1;
|
||||
} else if(radio3Selected==true && this.ceTab[1] == 0){
|
||||
this.grilleTab[this.cetteLigne][this.cetteColone] = LIBRE;
|
||||
notreCellule.setType(SORTIE);
|
||||
this.ceTab[0] = 1;
|
||||
} else if(this.ceTab[0] == 1 && this.ceType==ENTREE && radio1Selected==true){
|
||||
this.ceTab[0] = 0;
|
||||
} else if(this.ceTab[1] == 1 && this.ceType==SORTIE && radio1Selected==true){
|
||||
this.ceTab[1] = 0;
|
||||
}
|
||||
|
||||
|
||||
System.out.println("etat de la case maintenant : "+this.grilleTab[this.cetteLigne][this.cetteColone]);
|
||||
|
||||
}
|
||||
|
||||
public int[] getValues(){
|
||||
return this.ceTab;
|
||||
}
|
||||
|
||||
// Les méthodes suivantes ne sont pas utilisées dans cet exemple, donc nous les laissons vides
|
||||
public void mouseExited(MouseEvent e) {}
|
||||
public void mouseReleased(MouseEvent e) {}
|
||||
public void mousePressed(MouseEvent e) {}
|
||||
public void mouseEntered(MouseEvent e) {}
|
||||
}
|
@ -1,11 +1,11 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
public class creer implements ActionListener {
|
||||
public class Creer implements ActionListener {
|
||||
private String cet_event, f_option = "Nouvelle Grille";
|
||||
private JFrame cette_frame;
|
||||
|
||||
public creer(JFrame frame_initial){
|
||||
public Creer(JFrame frame_initial){
|
||||
super();
|
||||
this.cette_frame=frame_initial;
|
||||
}
|
||||
@ -14,8 +14,8 @@ public class creer implements ActionListener {
|
||||
this.cet_event=e.getActionCommand();
|
||||
this.cette_frame.dispose();
|
||||
if (cet_event.equals(f_option)){
|
||||
FenetreDefSize hehe = new FenetreDefSize();
|
||||
hehe.MiseEnPlace();
|
||||
FenetreDefSize fen = new FenetreDefSize();
|
||||
fen.MiseEnPlace();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
import java.awt.event.*;
|
||||
import javax.swing.JFrame;
|
||||
|
||||
public class importer implements ActionListener {
|
||||
public class Importer implements ActionListener {
|
||||
String cette_option;
|
||||
String cet_event;
|
||||
String ce_chemin;
|
||||
@ -11,7 +11,7 @@ public class importer implements ActionListener {
|
||||
int valeur0, valeur1, valeur2, valeur3, valeur4;
|
||||
|
||||
|
||||
public importer(JFrame une_frame){
|
||||
public Importer(JFrame une_frame){
|
||||
this.cette_option="Importer Grille";
|
||||
this.cette_frame = une_frame;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user