50 lines
1.3 KiB
Java
50 lines
1.3 KiB
Java
import java.awt.*;
|
|
import java.io.*;
|
|
import java.util.Arrays;
|
|
|
|
public class LectureFichier {
|
|
|
|
private Color[] tabCouleurs;
|
|
private String[] tabNomsCouleurs;
|
|
|
|
public LectureFichier() {
|
|
this.tabCouleurs = new Color[800];
|
|
this.tabNomsCouleurs = new String[800];
|
|
try {
|
|
BufferedReader lecture = new BufferedReader(new FileReader("rgb.txt"));
|
|
|
|
try {
|
|
String ligne = lecture.readLine();
|
|
int compteur = 0;
|
|
while (ligne != null) {
|
|
int r = Integer.parseInt(ligne.substring(0, 3).replaceAll(" ", "0"));
|
|
int g = Integer.parseInt(ligne.substring(4, 7).replaceAll(" ", "0"));
|
|
int b = Integer.parseInt(ligne.substring(8, 11).replaceAll(" ", "0"));
|
|
this.tabCouleurs[compteur] = new Color(r, g, b);
|
|
ligne = ligne.substring(11, ligne.length()).replaceAll(" ", "");
|
|
this.tabNomsCouleurs[compteur] = ligne;
|
|
ligne = lecture.readLine();
|
|
compteur++;
|
|
}
|
|
} catch (IOException e2) {
|
|
System.err.println("Erreur de lecture.");
|
|
}
|
|
try {
|
|
lecture.close();
|
|
} catch(IOException e3) {
|
|
System.err.println("Erreur de fermeture.");
|
|
}
|
|
} catch(IOException e) {
|
|
System.err.println("Erreur d'ouverture");
|
|
}
|
|
}
|
|
|
|
public Color[] getCouleurs() {
|
|
return this.tabCouleurs;
|
|
}
|
|
|
|
public String[] getNomsCouleurs() {
|
|
return this.tabNomsCouleurs;
|
|
}
|
|
|
|
} |