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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
|
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JComponent;
import javax.swing.JPanel;
public class Composant extends JComponent {
/**
*
*/
private static final long serialVersionUID = 1L;
private String colorName = "Tout";
private Color color = Color.RED;
private String forme = "Cercle";
private int taille = 30;
private int x = 100, y = 100;
private boolean allow = true;
private boolean listen = false;
public Composant() {
this.setSize(taille, taille);
this.setLocation(x, y);
System.out.println("on construit le composant");
}
@Override
public void paintComponent(Graphics g) {
super.paintComponents(g);
this.setLocation(x, y);
if (allow == true) {
if (colorName == "Rouge")
g.setColor(Color.RED);
else if (colorName == "Bleu")
g.setColor(Color.BLUE);
else if (colorName == "Tout") {
int r = (int) ((Math.random()) * 256);
int v = (int) ((Math.random()) * 256);
int b = (int) ((Math.random()) * 256);
color = new Color(r, v, b);
g.setColor(color);
}
if (forme == "Cercle") {
g.fillOval(0, 0, taille, taille);
System.out.println("x= " + x + " et y = " + y);
System.out.println(g.getColor());
}
// if (forme == "Carre")
// g.fillRect(x, y, taille, taille);
}
}
// if (listen == true) {
// g.setColor(Color.WHITE);
// g.fillRect(0, 0, this.getWidth(), this.getHeight());
// if (colorName == "Rouge")
// g.setColor(Color.RED);
// else if (colorName == "Bleu")
// g.setColor(Color.BLUE);
// else if (colorName == "Tout") {
// int r = (int) ((Math.random()) * 256);
// int v = (int) ((Math.random()) * 256);
// int b = (int) (Math.random() * 256);
//
// color = new Color(r, v, b);
// g.setColor(color);
// if (forme == "Cercle")
// g.drawOval(x, y, taille, taille);
//// if (forme == "Carre")
// g.drawRect(x, y, taille, taille);
// }
public String getColorName() {
return colorName;
}
public void setColorName(String colorName) {
this.colorName = colorName;
}
public boolean isAllow() {
return allow;
}
public void setAllow(boolean allow) {
this.allow = allow;
}
public String getForme() {
return forme;
}
public void setForme(String forme) {
this.forme = forme;
}
public int getTaille() {
return taille;
}
public void setTaille(int taille) {
this.taille = taille;
}
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
public boolean isListen() {
return listen;
}
public void setListen(boolean listen) {
this.listen = listen;
}
} |