UPDATE 11 - Premier pas sur l'ecriture

This commit is contained in:
fauvet 2023-04-18 18:38:32 +02:00
parent 180a4e23fe
commit 9db385a94a
13 changed files with 146 additions and 27 deletions

34
Enregistrer.java Normal file
View File

@ -0,0 +1,34 @@
import javax.swing.*;
import javax.swing.filechooser.FileNameExtensionFilter;
import java.io.*;
public class Enregistrer {
public Enregistrer(){
JFileChooser fileChooser = new JFileChooser();
fileChooser.setDialogTitle("Save file");
// Filtre pour n'afficher que les fichiers de type .txt
FileNameExtensionFilter filter = new FileNameExtensionFilter("Text files (*.txt)", "txt");
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(".txt")) {
fileToSave = new File(fileToSave.getAbsolutePath() + ".txt");
}
// Écrire du texte dans le fichier
try (BufferedWriter writer = new BufferedWriter(new FileWriter(fileToSave))) {
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());
}
}
}
}

27
ExporterFRG.java Normal file
View File

@ -0,0 +1,27 @@
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;
}
protected 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();
}
}

27
ExporterFVG.java Normal file
View File

@ -0,0 +1,27 @@
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;
}
protected 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.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();
}
}

View File

@ -4,25 +4,36 @@ 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 FenetreVideGrille(){
private JPanel[][] TabDePanel;
public FenetreVideGrille(int Taille){
super();
this.tab_de_int = new int[] {0, 0};
this.Taille = Taille;
this.TabDePanel = new JPanel[this.Taille][this.Taille];
}
protected void create_empty(int Taille){
protected void CreerVide(){
this.fenetre.setSize(600, 600);
this.fenetre.setLocation(450, 200);
OptionsFVG un_Test = new OptionsFVG(this);
un_Test.set_up();
un_Test.SetUp();
GridLayout gestionnaire = new GridLayout(Taille,Taille);
this.fenetre.setLayout(gestionnaire);
for(int i=0; i<Taille; i++){
for(int j=0; j<Taille; j++){
for(int i=0; i<this.Taille; i++){
for(int j=0; j<this.Taille; j++){
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);
@ -35,4 +46,18 @@ public class FenetreVideGrille extends Fenetre{
}
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;
}
}

BIN
Grand.lab Normal file

Binary file not shown.

View File

@ -67,7 +67,7 @@ public class Lecture {
int cette_taille=fis.available();/*cette_taille prend une aproximation de la taille du flux */
int ce_compteur = 0, temp;
int [] ce_tableau = new int[cette_taille-4]; /*-5 pour le header mais +1 pour le -1 de fin de fichier. */
int [] ce_tableau = new int[cette_taille]; /*-5 pour le header mais +1 pour le -1 de fin de fichier. */
int [] ce_tableau_temp = new int[8]; /*C'est le tab qui va stocker les différents octets */
int[] ce_tab_to_return = new int[0];; /*Tableau qui va être renvoyé et qui va contenir tous les bits dans le non ordre */

View File

@ -3,7 +3,7 @@ import java.awt.event.*;
public class OptionsBoutonsFRG implements ActionListener{
private String Reponses1="Quitter", Reponses2="Sauvegarder";
private String cet_event;
private Exporter test;
private ExporterFRG test;
private FenetreRndmGrille ce_frg;
protected OptionsBoutonsFRG(FenetreRndmGrille un_frg){
@ -17,7 +17,7 @@ public class OptionsBoutonsFRG implements ActionListener{
}
else if (cet_event.equals(this.Reponses2)){
System.out.println("Test1");
this.test = new Exporter(this.ce_frg);
this.test = new ExporterFRG(this.ce_frg);
this.test.jsp();
}
}

View File

@ -3,17 +3,21 @@ 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;
protected OptionsBoutonsFVG(FenetreVideGrille FVG){
protected 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)){
}
} else if (cet_event.equals(this.Reponses2)){
System.out.println("Test1");
this.test = new ExporterFVG(this.ce_fvg);
this.test.jsp();
}
}
}

View File

@ -109,9 +109,9 @@ public class OptionsFRG extends Fenetre {
/* */
OptionsBoutonsFRG hahaha = new OptionsBoutonsFRG(this.ce_frg);
un_Button1.addActionListener(hahaha);
un_Button2.addActionListener(hahaha);
OptionsBoutonsFRG ces_options = new OptionsBoutonsFRG(this.ce_frg);
un_Button1.addActionListener(ces_options);
un_Button2.addActionListener(ces_options);
/* Evenement */

View File

@ -5,15 +5,16 @@ public class OptionsFVG extends Fenetre {
public JRadioButton radio1;
public JRadioButton radio2;
public JRadioButton radio3;
private FenetreVideGrille FVG;
private FenetreVideGrille ce_fvg;
public OptionsFVG(FenetreVideGrille FVG) {
public OptionsFVG(FenetreVideGrille un_fvg) {
super();
this.fenetre.setSize(400, 600);
this.fenetre.setLocation(1100, 200);
this.ce_fvg=un_fvg;
}
protected void set_up(){
protected void SetUp(){
GridLayout gestionnaire = new GridLayout(4,1);
this.fenetre.setLayout(gestionnaire);
@ -38,7 +39,7 @@ public class OptionsFVG extends Fenetre {
/*Création du deuxième panneau */
JPanel un_Panel3 = new JPanel();
JButton un_Button1 = new JButton("Sauvegrder");
JButton un_Button1 = new JButton("Sauvegarder");
JPanel un_Panel4 = new JPanel();
un_Panel4.add(un_Button1);
@ -108,9 +109,9 @@ public class OptionsFVG extends Fenetre {
/* */
OptionsBoutonsFVG hahaha = new OptionsBoutonsFVG(this.FVG);
un_Button1.addActionListener(hahaha);
un_Button2.addActionListener(hahaha);
OptionsBoutonsFVG ces_options = new OptionsBoutonsFVG(this.ce_fvg);
un_Button1.addActionListener(ces_options);
un_Button2.addActionListener(ces_options);
/* Evenement */

View File

@ -27,6 +27,7 @@ public class importer implements ActionListener {
/*lecture du fichier */
this.cette_lecture = new Lecture(this.ce_chemin);
this.valeur0=this.cette_lecture.GetHeader(0);
this.valeur1=this.cette_lecture.GetHeader(1);
this.valeur2=this.cette_lecture.GetHeader(2);

View File

@ -2,7 +2,7 @@ public class outils {
protected outils(){
}
public int[] reverse(int[] un_tableau) {
public static int[] reverse(int[] un_tableau) {
int taille = un_tableau.length;
int[] cette_copie;
@ -17,7 +17,7 @@ public class outils {
return cette_copie;
}
public int[] concatenate(int[] first_tab, int[] tab_to_add){
public static int[] concatenate(int[] first_tab, int[] tab_to_add){
int taille = first_tab.length;
int[] tableau_temp = new int[taille+tab_to_add.length];

View File

@ -23,8 +23,8 @@ public class taille_su extends JFrame implements ActionListener {
}
else if(this.ce_group.getSelection().getActionCommand()=="Grille vide"){
FenetreVideGrille cette_fenetre = new FenetreVideGrille();
cette_fenetre.create_empty(Integer.parseInt(valleur_taille));
FenetreVideGrille cette_fenetre = new FenetreVideGrille(Integer.parseInt(valleur_taille));
cette_fenetre.CreerVide();
}
}
}