Fin de tout
This commit is contained in:
Binary file not shown.
@@ -5,14 +5,16 @@ import java.awt.*;
|
||||
public class GestionSouris implements MouseListener {
|
||||
|
||||
private Fenetre fenetre;
|
||||
private Rectangle rect;
|
||||
private JPanel rect;
|
||||
private int debutX;
|
||||
private int debutY;
|
||||
private int finX;
|
||||
private int finY;
|
||||
private boolean rectActif;
|
||||
|
||||
public GestionSouris(Fenetre fenetre) {
|
||||
this.fenetre = fenetre;
|
||||
this.rectActif = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -26,32 +28,28 @@ public class GestionSouris implements MouseListener {
|
||||
}
|
||||
|
||||
public void mousePressed(MouseEvent evenement){
|
||||
if (this.rectActif) {
|
||||
this.fenetre.remove(this.rect);
|
||||
}
|
||||
System.out.println("Appui simple");
|
||||
this.fenetre.add(new Rectangle(evenement.getX(), evenement.getY(), evenement.getX()+200, evenement.getY()+200));
|
||||
this.debutX = evenement.getX();
|
||||
this.debutY = evenement.getY();
|
||||
this.rect = new Rectangle(this.debutX, this.debutY, evenement.getX(), evenement.getY());
|
||||
//this.fenetre.add(rect);
|
||||
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);
|
||||
this.fenetre.repaint();
|
||||
}
|
||||
|
||||
public void mouseReleased(MouseEvent evenement){
|
||||
this.finX = evenement.getX();
|
||||
this.finY = evenement.getY();
|
||||
this.rectActif = true;
|
||||
}
|
||||
|
||||
public int getDebutX() {
|
||||
return this.debutX;
|
||||
}
|
||||
|
||||
public int getDebutY() {
|
||||
return this.debutY;
|
||||
}
|
||||
|
||||
public void setRect(int finX, int finY) {
|
||||
this.rect.setBounds(this.debutX, this.debutY, finX, finY);
|
||||
System.out.println("debut : [" + this.debutX + ", " + this.debutY + "]");
|
||||
System.out.println("fin : [" + finX + ", " + finY + "]");
|
||||
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 + "]");
|
||||
this.fenetre.repaint();
|
||||
}
|
||||
}
|
BIN
DEV2.1/TP09/03_Rectangle/Rect.class
Normal file
BIN
DEV2.1/TP09/03_Rectangle/Rect.class
Normal file
Binary file not shown.
@@ -1,14 +1,14 @@
|
||||
import java.awt.*;
|
||||
import javax.swing.*;
|
||||
|
||||
public class Rectangle extends JComponent {
|
||||
public class Rect extends JComponent {
|
||||
|
||||
private int departX;
|
||||
private int departY;
|
||||
private int finX;
|
||||
private int finY;
|
||||
|
||||
public Rectangle(int departX, int departY, int finX, int finY) {
|
||||
public Rect(int departX, int departY, int finX, int finY) {
|
||||
this.departX = departX;
|
||||
this.departY = departY;
|
||||
this.finX = finX;
|
Reference in New Issue
Block a user