1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
| import java.awt.Color;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import acm.graphics.GLabel;
import acm.graphics.GRect;
import acm.program.GraphicsProgram;
public class sudo1 extends GraphicsProgram{
public GRect fond;
public int bord = 100;
public int tailleCase = 50 ;
public int espaceCase = 10 ;
public GRect [][] bloc = new GRect[3][3];
public GRect [][] cellule = new GRect[9][9];
public static int [][] valCase = new int [9][9];
public int [][] modifCase = new int [9][9];
public static GLabel [][] texteCase = new GLabel[9][9];
public void init() {
fond = new GRect(bord,bord,9*tailleCase+10*espaceCase,9*tailleCase+10*espaceCase);
fond.setFillColor(Color.BLUE);
fond.setFilled(true);
add(fond);
//Création des blocs 3x3 :
for (int indX=0; indX<3;indX++) {
for (int indY=0; indY<3;indY++) {
bloc[indX][indY]= new GRect(bord+espaceCase+indX*3*espaceCase+indX*3*tailleCase,bord+espaceCase+indY*3*espaceCase+indY*3*tailleCase,
3*tailleCase+2*espaceCase,3*tailleCase+2*espaceCase);
bloc[indX][indY].setFillColor(Color.WHITE);
bloc[indX][indY].setFilled(true);
add(bloc[indX][indY]);
}
}
// création des cases :
for (int indX=0; indX<9;indX++) {
for (int indY=0; indY<9;indY++) {
cellule[indX][indY]= new GRect(bord+(1+indX)*espaceCase+indX*tailleCase,bord+(1+indY)*espaceCase+indY*tailleCase, tailleCase,tailleCase);
cellule[indX][indY].setFillColor(Color.LIGHT_GRAY);
cellule[indX][indY].setFilled(true);
add(cellule[indX][indY]);
valCase[indX][indY]=indX;
texteCase[indX][indY] = new GLabel(String.valueOf(valCase[indX][indY]),bord+(1+indX)*espaceCase+(0.4+indX)*tailleCase,
bord+(1+indY)*espaceCase+(0.6+indY)*tailleCase);
add(texteCase[indX][indY]);
}
}
//lecture();
ecriture();
}
public static void ecriture() {
String ligne ;
int nombre = 123;
BufferedWriter fichier;
try {
fichier = new BufferedWriter(new FileWriter("Toto.txt"));
fichier.write("bonjour tout le monde");
fichier.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("fichier créé");
}
public static void lecture() throws IOException {
int table[] = new int[100];
BufferedReader Lecteur = null;
try {
Lecteur = new BufferedReader(new FileReader("Toto.txt"));
}
catch(FileNotFoundException exc) {
System.out.println("erreur");
}
String[] ligne = new String[1000];
int index = 0;
index = 0;
while ((ligne[index] = Lecteur.readLine()) != null) {
System.out.print("ligne : ");
System.out.print(index);
System.out.print(" > ");
System.out.println(ligne[index]);
table[index]=Integer.parseInt(ligne[index]);
index++;
}
for (int indX=0; indX<3;indX++) {
for (int indY=0; indY<3;indY++) {
valCase[indX][indY]= table[indX+9*indY];
texteCase[indX][indY].setLabel(String.valueOf(valCase[indX][indY]));
}
}
}
} |
Partager