2023-11-20 13:22:30 +01:00
|
|
|
import java.util.*;
|
2023-11-29 16:08:44 +01:00
|
|
|
import java.io.*;
|
|
|
|
import javax.swing.*;
|
|
|
|
import java.awt.*;
|
2023-11-20 13:22:30 +01:00
|
|
|
|
2023-11-29 16:08:44 +01:00
|
|
|
public class Q2Main{
|
2023-11-20 13:22:30 +01:00
|
|
|
public static void main(String args[]){
|
2023-11-29 16:08:44 +01:00
|
|
|
String nomFichier = "rgb.txt";
|
|
|
|
HashMap<String,Color> dicoCouleur = new HashMap<>();
|
|
|
|
DefaultListModel<String> listeCouleur = new DefaultListModel<>();
|
2023-11-20 13:22:30 +01:00
|
|
|
try{
|
2023-11-29 16:08:44 +01:00
|
|
|
BufferedReader lecture = new BufferedReader(new FileReader(nomFichier));
|
2023-11-20 13:22:30 +01:00
|
|
|
String ligne;
|
|
|
|
|
|
|
|
try {
|
|
|
|
while ((ligne = lecture.readLine()) != null) {
|
2023-11-29 16:08:44 +01:00
|
|
|
int rouge = Integer.parseInt(ligne.substring(0,3).trim());
|
|
|
|
int vert = Integer.parseInt(ligne.substring(4,7).trim());
|
|
|
|
int bleu = Integer.parseInt(ligne.substring(8,11).trim());
|
|
|
|
Color couleur = new Color(rouge, vert, bleu);
|
|
|
|
String nom = ligne.substring(13).trim();
|
2023-11-20 13:22:30 +01:00
|
|
|
dicoCouleur.put(nom, couleur);
|
2023-11-29 16:08:44 +01:00
|
|
|
listeCouleur.addElement(nom);
|
2023-11-20 13:22:30 +01:00
|
|
|
}
|
|
|
|
} 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 !");
|
|
|
|
}
|
|
|
|
|
2023-11-29 16:08:44 +01:00
|
|
|
JList<String> menuDeroulant = new JList<>(listeCouleur);
|
|
|
|
JScrollPane ascensseur = new JScrollPane(menuDeroulant);
|
2023-11-20 13:22:30 +01:00
|
|
|
JFrame fenetre = new JFrame();
|
|
|
|
fenetre.setSize(700, 300);
|
|
|
|
fenetre.setLocation(0, 0);
|
|
|
|
fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
2023-11-29 16:08:44 +01:00
|
|
|
|
|
|
|
JPanel contenu = new JPanel(new BorderLayout());
|
|
|
|
contenu.setBackground(Color.RED);
|
|
|
|
contenu.add(ascensseur, BorderLayout.WEST);
|
|
|
|
fenetre.add(contenu, BorderLayout.CENTER);
|
2023-11-20 13:22:30 +01:00
|
|
|
fenetre.setVisible(true);
|
|
|
|
|
|
|
|
} catch(FileNotFoundException e) {
|
|
|
|
System.err.println("Erreur d'ouverture de rgb.txt !");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|