37 lines
1.2 KiB
Java
37 lines
1.2 KiB
Java
|
import javax.swing.*;
|
||
|
import java.awt.*;
|
||
|
import java.awt.event.*;
|
||
|
public class Rectangle extends JComponent{
|
||
|
int xOrigine;
|
||
|
int yOrigine;
|
||
|
int yDestination;
|
||
|
int xDestination;
|
||
|
int longueurFenetre;
|
||
|
int hauteurFenetre;
|
||
|
|
||
|
public Rectangle(){
|
||
|
this.xOrigine = -1;
|
||
|
this.yOrigine = -1;
|
||
|
this.xDestination = -1;
|
||
|
this.yDestination = -1;
|
||
|
this.longueurFenetre = this.getWidth();
|
||
|
this.hauteurFenetre = this.getHeight();
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
protected void paintComponent(Graphics pinceau) {
|
||
|
Graphics secondPinceau = pinceau.create();
|
||
|
secondPinceau.setColor(new Color(0,0,0));
|
||
|
secondPinceau.fillRect(0, 0, this.getWidth(), this.getHeight());
|
||
|
secondPinceau.setColor(new Color(0,255,100));
|
||
|
|
||
|
if (this.xOrigine >= 0 && this.yOrigine >= 0){
|
||
|
int newXOrigine = this.getWidth()*this.xOrigine/this.longueurFenetre;
|
||
|
int newYOrigine = this.getHeight()*this.yOrigine/this.hauteurFenetre;
|
||
|
int newLongueur = this.getWidth()*(this.xDestination-this.xOrigine)/this.longueurFenetre;
|
||
|
int newHauteur = this.getHeight()*(this.yDestination-this.yOrigine)/this.hauteurFenetre;
|
||
|
secondPinceau.fillRect(newXOrigine,newXOrigine,newLongueur,newHauteur);
|
||
|
}
|
||
|
}
|
||
|
}
|