2025-03-12 17:10:44 +01:00
|
|
|
import java.awt.event.*;
|
|
|
|
import javax.swing.*;
|
|
|
|
import java.awt.*;
|
|
|
|
|
|
|
|
public class GestionSouris implements MouseListener {
|
|
|
|
|
|
|
|
private Fenetre fenetre;
|
2025-03-17 10:11:05 +01:00
|
|
|
private JPanel rect;
|
2025-03-12 17:10:44 +01:00
|
|
|
private int debutX;
|
|
|
|
private int debutY;
|
|
|
|
private int finX;
|
|
|
|
private int finY;
|
2025-03-17 10:11:05 +01:00
|
|
|
private boolean rectActif;
|
2025-03-12 17:10:44 +01:00
|
|
|
|
|
|
|
public GestionSouris(Fenetre fenetre) {
|
|
|
|
this.fenetre = fenetre;
|
2025-03-17 10:11:05 +01:00
|
|
|
this.rectActif = false;
|
2025-03-12 17:10:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void mouseClicked(MouseEvent evenement) {
|
|
|
|
}
|
|
|
|
|
|
|
|
public void mouseEntered(MouseEvent evenement){
|
|
|
|
}
|
|
|
|
|
|
|
|
public void mouseExited(MouseEvent evenement){
|
|
|
|
}
|
|
|
|
|
|
|
|
public void mousePressed(MouseEvent evenement){
|
2025-03-17 10:11:05 +01:00
|
|
|
if (this.rectActif) {
|
|
|
|
this.fenetre.remove(this.rect);
|
|
|
|
}
|
2025-03-12 17:10:44 +01:00
|
|
|
System.out.println("Appui simple");
|
2025-03-17 10:11:05 +01:00
|
|
|
this.rect = new JPanel();
|
|
|
|
this.rect.setOpaque(true);
|
|
|
|
this.rect.setBackground(Color.BLUE);
|
|
|
|
this.debutX = evenement.getX()-4; // Le -4 est du à un décalage de la méthode getX jsp pourquoi sah
|
|
|
|
this.debutY = evenement.getY()-26; // Pareil pour le -26
|
|
|
|
this.fenetre.add(this.rect);
|
2025-03-12 17:10:44 +01:00
|
|
|
this.fenetre.repaint();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void mouseReleased(MouseEvent evenement){
|
2025-03-17 10:11:05 +01:00
|
|
|
this.rectActif = true;
|
2025-03-12 17:10:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setRect(int finX, int finY) {
|
2025-03-17 10:11:05 +01:00
|
|
|
System.out.println(this.debutX + " " + this.debutY + " " + (finX-this.debutX+5) + " " + (finY-this.debutY-10) + "");
|
|
|
|
this.rect.setBounds(this.debutX, this.debutY, finX-this.debutX-4, finY-this.debutY-26); // Décalage encore
|
|
|
|
//System.out.println("debut : [" + this.debutX + ", " + this.debutY + "]");
|
|
|
|
//System.out.println("fin : [" + finX + ", " + finY + "]");
|
2025-03-12 17:10:44 +01:00
|
|
|
this.fenetre.repaint();
|
|
|
|
}
|
|
|
|
}
|