fin tp3
This commit is contained in:
BIN
DEV3.2/TP03/03_Tableau/ControleurParallelogramme.class
Normal file
BIN
DEV3.2/TP03/03_Tableau/ControleurParallelogramme.class
Normal file
Binary file not shown.
45
DEV3.2/TP03/03_Tableau/ControleurParallelogramme.java
Normal file
45
DEV3.2/TP03/03_Tableau/ControleurParallelogramme.java
Normal file
@@ -0,0 +1,45 @@
|
||||
import java.awt.*;
|
||||
import javax.swing.*;
|
||||
import java.awt.event.MouseListener;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class ControleurParallelogramme implements MouseListener {
|
||||
|
||||
private CouleurList<Color> listeCouleurs;
|
||||
private Fenetre fenetre;
|
||||
|
||||
public ControleurParallelogramme(CouleurList<Color> listeCouleurs, Fenetre fenetre) {
|
||||
this.listeCouleurs = listeCouleurs;
|
||||
this.fenetre = fenetre;
|
||||
|
||||
}
|
||||
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
try {
|
||||
Robot robot = new Robot();
|
||||
Color couleurPixel = robot.getPixelColor(e.getXOnScreen(), e.getYOnScreen());
|
||||
Color aSupprimer = null;
|
||||
for (Color couleur : this.listeCouleurs) {
|
||||
if (couleur.equals(couleurPixel)) {
|
||||
aSupprimer = couleur;
|
||||
System.out.println("Luminance : " + (couleur.getRed()*21 + couleur.getGreen()*72 + couleur.getBlue()*7));
|
||||
}
|
||||
}
|
||||
if (aSupprimer != null) {
|
||||
this.listeCouleurs.remove(aSupprimer);
|
||||
this.fenetre.getP().repaint();
|
||||
}
|
||||
} catch (AWTException exception) {
|
||||
System.err.println("Erreur du système");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void mouseEntered(MouseEvent e) {}
|
||||
public void mouseExited(MouseEvent e) {}
|
||||
public void mousePressed(MouseEvent e) {}
|
||||
public void mouseReleased(MouseEvent e) {}
|
||||
}
|
BIN
DEV3.2/TP03/03_Tableau/CouleurList.class
Normal file
BIN
DEV3.2/TP03/03_Tableau/CouleurList.class
Normal file
Binary file not shown.
49
DEV3.2/TP03/03_Tableau/CouleurList.java
Normal file
49
DEV3.2/TP03/03_Tableau/CouleurList.java
Normal file
@@ -0,0 +1,49 @@
|
||||
import java.awt.*;
|
||||
import javax.swing.*;
|
||||
import java.util.List;
|
||||
import java.util.Iterator;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class CouleurList<E> implements Iterable<E> {
|
||||
|
||||
protected E[] valeurs;
|
||||
|
||||
public CouleurList() {
|
||||
this.valeurs = (E[]) new Object[10];
|
||||
}
|
||||
|
||||
public CouleurList(E element) {
|
||||
this.valeurs = (E[]) new Object[10];
|
||||
this.valeurs[0] = element;
|
||||
}
|
||||
|
||||
public void add(E element) {
|
||||
for (int i = 0; i != this.valeurs.length; i++) {
|
||||
if (this.valeurs[i] == null) {
|
||||
this.valeurs[i] = element;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean remove(E element) {
|
||||
for (int i = 0; i != this.valeurs.length; i++) {
|
||||
if (this.valeurs[i] != null && this.valeurs[i].equals(element)) {
|
||||
for (int j = i; j != this.valeurs.length-1; j++) {
|
||||
this.valeurs[j] = this.valeurs[j+1];
|
||||
}
|
||||
this.valeurs[this.valeurs.length - 1] = null;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<E> iterator() {
|
||||
return new Iterateur(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
BIN
DEV3.2/TP03/03_Tableau/Fenetre.class
Normal file
BIN
DEV3.2/TP03/03_Tableau/Fenetre.class
Normal file
Binary file not shown.
39
DEV3.2/TP03/03_Tableau/Fenetre.java
Normal file
39
DEV3.2/TP03/03_Tableau/Fenetre.java
Normal file
@@ -0,0 +1,39 @@
|
||||
import java.awt.*;
|
||||
import javax.swing.*;
|
||||
import java.util.Random;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Fenetre extends JFrame {
|
||||
|
||||
private JParallelogramme p;
|
||||
|
||||
public Fenetre() {
|
||||
this.setSize(300, 100);
|
||||
this.setLocation(100, 100);
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
this.setLayout(new FlowLayout(FlowLayout.CENTER));
|
||||
|
||||
CouleurList<Color> listeCouleurs = new CouleurList<>();
|
||||
|
||||
int r, g, b;
|
||||
Random aleatoire = new Random();
|
||||
|
||||
for (int i = 0; i != 10; i++) {
|
||||
r = Math.abs(aleatoire.nextInt()) % 255;
|
||||
g = Math.abs(aleatoire.nextInt()) % 255;
|
||||
b = Math.abs(aleatoire.nextInt()) % 255;
|
||||
listeCouleurs.add(new Color(r, g, b));
|
||||
}
|
||||
|
||||
this.p = new JParallelogramme(listeCouleurs);
|
||||
|
||||
p.addMouseListener(new ControleurParallelogramme(listeCouleurs, this));
|
||||
|
||||
this.add(p);
|
||||
}
|
||||
|
||||
public JParallelogramme getP() {
|
||||
return this.p;
|
||||
}
|
||||
}
|
BIN
DEV3.2/TP03/03_Tableau/Iterateur.class
Normal file
BIN
DEV3.2/TP03/03_Tableau/Iterateur.class
Normal file
Binary file not shown.
32
DEV3.2/TP03/03_Tableau/Iterateur.java
Normal file
32
DEV3.2/TP03/03_Tableau/Iterateur.java
Normal file
@@ -0,0 +1,32 @@
|
||||
import java.awt.*;
|
||||
import javax.swing.*;
|
||||
import java.util.List;
|
||||
import java.util.Iterator;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
public class Iterateur<T> implements Iterator<T> {
|
||||
|
||||
private CouleurList<T> liste;
|
||||
private int indice;
|
||||
|
||||
public Iterateur(CouleurList liste) {
|
||||
this.liste = liste;
|
||||
this.indice = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return this.indice < 10 && this.liste.valeurs[indice] != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T next() {
|
||||
if (!hasNext()) {
|
||||
throw new java.util.NoSuchElementException();
|
||||
}
|
||||
return this.liste.valeurs[this.indice++];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
BIN
DEV3.2/TP03/03_Tableau/JParallelogramme.class
Normal file
BIN
DEV3.2/TP03/03_Tableau/JParallelogramme.class
Normal file
Binary file not shown.
46
DEV3.2/TP03/03_Tableau/JParallelogramme.java
Normal file
46
DEV3.2/TP03/03_Tableau/JParallelogramme.java
Normal file
@@ -0,0 +1,46 @@
|
||||
import java.awt.*;
|
||||
import javax.swing.*;
|
||||
import java.util.Random;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class JParallelogramme extends JComponent {
|
||||
|
||||
private CouleurList<Color> listeCouleurs;
|
||||
|
||||
public JParallelogramme(CouleurList<Color> 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 CouleurList<Color> getListeCouleurs() {
|
||||
return this.listeCouleurs;
|
||||
}
|
||||
}
|
BIN
DEV3.2/TP03/03_Tableau/Main.class
Normal file
BIN
DEV3.2/TP03/03_Tableau/Main.class
Normal file
Binary file not shown.
6
DEV3.2/TP03/03_Tableau/Main.java
Normal file
6
DEV3.2/TP03/03_Tableau/Main.java
Normal file
@@ -0,0 +1,6 @@
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
Fenetre fenetre = new Fenetre();
|
||||
fenetre.setVisible(true);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user