Files
DEV/DEV2.1/TP05/Nuance.java

51 lines
1.3 KiB
Java
Raw Normal View History

2025-02-10 21:02:57 +01:00
import java.awt.*;
import javax.swing.*;
public class Nuance extends JPanel {
2025-02-25 15:23:34 +01:00
private int r;
private int g;
private int b;
public Nuance(int[] couleurs) {
2025-02-10 21:02:57 +01:00
super();
2025-02-25 15:23:34 +01:00
this.r = couleurs[0];
this.g = couleurs[1];
this.b = couleurs[2];
this.setPreferredSize(new Dimension(100,100));
this.afficheNuance();
}
public void afficheNuance() {
this.setBackground(new Color(this.r, this.g, this.b));
BorderLayout layout = new BorderLayout();
this.setLayout(layout);
JLabel texte_superieur = new JLabel(this.r + "," + this.g + "," + this.b);
texte_superieur.setHorizontalAlignment(JLabel.CENTER);
texte_superieur.setOpaque(true);
texte_superieur.setForeground(Color.WHITE);
texte_superieur.setBackground(Color.BLACK);
this.add(texte_superieur, BorderLayout.NORTH);
2025-02-10 21:02:57 +01:00
}
2025-02-25 15:23:34 +01:00
public static void main(String[] args) {
JFrame fenetre = new JFrame();
fenetre.setLocation(100,100);
fenetre.setLayout(new FlowLayout());
fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
for (String element : args) {
element = element.replaceAll("#", "");
int[] couleurs = {
Integer.parseInt(element.substring(0,2), 16),
Integer.parseInt(element.substring(2,4), 16),
Integer.parseInt(element.substring(4,6), 16)
};
fenetre.add(new Nuance(couleurs));
}
fenetre.pack();
fenetre.setVisible(true);
}
2025-02-10 21:02:57 +01:00
}