This commit is contained in:
Simoes Lukas
2025-11-06 15:20:51 +01:00
parent 9b1257f3da
commit c730f07c1b
13 changed files with 874 additions and 8 deletions

View File

@@ -0,0 +1,48 @@
import java.io.*;
import java.util.Map;
import java.util.HashMap;
import java.util.Arrays;
import java.awt.*;
public class LectureFichier {
private Map<String, Color> dictCouleurs;
public LectureFichier() {
this.dictCouleurs = new HashMap<>();
try {
BufferedReader lecture = new BufferedReader(new FileReader("rgb.txt"));
try {
String ligne = lecture.readLine();
while(ligne != null) {
String r = ligne.substring(0, 3).trim();
String g = ligne.substring(4, 7).trim();
String b = ligne.substring(8, 11).trim();
String nomCouleur = ligne.substring(11).strip();
this.dictCouleurs.put(nomCouleur, new Color(Integer.parseInt(r), Integer.parseInt(g), Integer.parseInt(b)));
ligne = lecture.readLine();
}
} catch(IOException e) {
System.err.println("Erreur de lecture dans rgb.txt !");
}
try {
lecture.close();
} catch(IOException e) {
System.err.println("Erreur de fermeture de rgb.txt !");
}
} catch(FileNotFoundException e) {
System.err.println("Erreur d'ouverture de rgb.txt !");
}
}
public Map<String, Color> getDictCouleurs() {
return this.dictCouleurs;
}
}