tp3
This commit is contained in:
BIN
DEV3.2/TP03/01_Luminance/ControleurParallelogramme.class
Normal file
BIN
DEV3.2/TP03/01_Luminance/ControleurParallelogramme.class
Normal file
Binary file not shown.
45
DEV3.2/TP03/01_Luminance/ControleurParallelogramme.java
Normal file
45
DEV3.2/TP03/01_Luminance/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 List<Color> listeCouleurs;
|
||||
private Fenetre fenetre;
|
||||
|
||||
public ControleurParallelogramme(List<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/01_Luminance/Fenetre.class
Normal file
BIN
DEV3.2/TP03/01_Luminance/Fenetre.class
Normal file
Binary file not shown.
39
DEV3.2/TP03/01_Luminance/Fenetre.java
Normal file
39
DEV3.2/TP03/01_Luminance/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));
|
||||
|
||||
List<Color> listeCouleurs = new ArrayList<Color>();
|
||||
|
||||
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/01_Luminance/JParallelogramme.class
Normal file
BIN
DEV3.2/TP03/01_Luminance/JParallelogramme.class
Normal file
Binary file not shown.
47
DEV3.2/TP03/01_Luminance/JParallelogramme.java
Normal file
47
DEV3.2/TP03/01_Luminance/JParallelogramme.java
Normal file
@@ -0,0 +1,47 @@
|
||||
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<Color> listeCouleurs;
|
||||
private List<Polygon> listePolygones;
|
||||
|
||||
public JParallelogramme(List<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 List<Color> getListeCouleurs() {
|
||||
return this.listeCouleurs;
|
||||
}
|
||||
}
|
BIN
DEV3.2/TP03/01_Luminance/Main.class
Normal file
BIN
DEV3.2/TP03/01_Luminance/Main.class
Normal file
Binary file not shown.
6
DEV3.2/TP03/01_Luminance/Main.java
Normal file
6
DEV3.2/TP03/01_Luminance/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