1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
| public class Ecran extends JPanel implements MouseListener{
public Ecran(Etat etat, Grandeur grandeur, Envoi envoi, MainAppli app) {
}
public void mouseClicked(MouseEvent arg0) {
switch(choix){
case 'r' :
if(x == 0){
x = arg0.getX();
y = arg0.getY();
app.removeListener();
}
else{
xf = arg0.getX();
yf = arg0.getY();
app.ajoutListener();
add(new Rectangle(x, y, xf, yf, envoi, ecran));
}
break;
}
}
}
class Rectangle extends JPanel{
int x, y, xf, yf;
Envoi envoi;
Ecran ecran;
public Rectangle(int x, int y, int xf, int yf, Envoi envoi, Ecran ecran){
this.x = x;
this.y = y;
this.xf = xf;
this.yf = yf;
this.envoi = envoi;
this.ecran = ecran;
}
public void paintComponent(Graphics g){
super.paintComponent(g);
System.out.println("coucou");
g.setColor(Color.BLACK);
setVisible(true);
g.drawRect(x, y, xf-x, yf-y);
}
} |
Partager