import java.awt.*; import javax.swing.*; import java.util.Random; import java.util.List; import java.util.ArrayList; public class JParallelogramme extends JComponent { private List listeCouleurs; private List listePolygones; public JParallelogramme(List listeCouleurs) { this.setPreferredSize(new Dimension(280, 60)); this.listeCouleurs = listeCouleurs; } @Override public void paintComponent(Graphics pinceau) { Graphics secondPinceau = pinceau.create(); if (this.isOpaque()) { secondPinceau.setColor(this.getBackground()); secondPinceau.fillRect(0, 0, this.getWidth(), this.getHeight()); } int[] x = {30, 50, 20, 0}; int[] y = {0, 0, this.getHeight(), this.getHeight()}; for (Color couleur : this.listeCouleurs) { secondPinceau.setColor(couleur); secondPinceau.fillPolygon(x, y, 4); secondPinceau.setColor(Color.DARK_GRAY); secondPinceau.drawPolygon(x, y, 4); for (int j = 0; j != 4; j++) { x[j] += 25; } } } public List getListeCouleurs() { return this.listeCouleurs; } }