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 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
| import javax.swing.*;
import java.awt.*;
class Dessin extends JPanel {
private int r1= 0;
private int r2= 0;
private int r3= 0;
private int r4= 0;
private int r5= 0;
private int r6= 0;
private int r7 = 250;
private int b1 = 250;
private int b2 = 250;
private int b3 = 250;
private int b4 = 250;
private int b5 = 250;
private int b6 = 250;
private int b7 = 250;
//---------getters & setters indicés---------
private int b[]=new int[30000];
public int getB(int l){
return b[l];
}
public void setB(int l, int o){
this.b[l]=0;
}
//====================================================
//getters et setters
public int getR1() {
return r1;
}
public void setR1(int r1) {
this.r1 = r1;
}
public int getR2() {
return r2;
}
public void setR2(int r2) {
this.r2 = r2;
}
public int getR3() {
return r3;
}
public void setR3(int r3) {
this.r3 = r3;
}
public int getR4() {
return r4;
}
public void setR4(int r4) {
this.r4 = r4;
}
public int getR5() {
return r5;
}
public void setR5(int r5) {
this.r5 = r5;
}
public int getR6() {
return r6;
}
public void setR6(int r6) {
this.r6 = r6;
}
public int getB1() {
return b1;
}
public void setB1(int b1) {
this.b1 = b1;
}
public int getB2() {
return b2;
}
public void setB2(int b2) {
this.b2 = b2;
}
public int getB3() {
return b3;
}
public void setB3(int b3) {
this.b3 = b3;
}
public int getB4() {
return b4;
}
public void setB4(int b4) {
this.b4 = b4;
}
public int getB5() {
return b5;
}
public void setB5(int b5) {
this.b5 = b5;
}
public int getB6() {
return b6;
}
public void setB6(int b6) {
this.b6 = b6;
}
public int getR7() {
return r7;
}
public void setR7(int r7) {
this.r7 = r7;
}
public int getB7() {
return b7;
}
public void setB7(int b7) {
this.b7 = b7;
}
//==============================================
public void paintComponent(Graphics g)
{ Graphics2D g2d = (Graphics2D)g;
super.paintComponent(g);
Color c = g.getColor();
//rectangle 1
g2d.setColor(new Color(r1, 0, b1));
g2d.fillRect(0,0,50,200);
//rectangle 2 et 3
g2d.setColor(new Color(r2, 0, b2));
g2d.fillRect(50,0,50,50);
g2d.setColor(new Color(r3, 0, b3));
g2d.fillRect(50,150,50,50);
//rectangle 4 et 5
g2d.setColor(new Color(r4, 0, b4));
g2d.fillRect(50,50,25,100);
g2d.setColor(new Color(r5, 0, b5));
g2d.fillRect(75,50,25,100);
//rectangle 6 et 7
g2d.setColor(new Color(r6, 0, b6));
g2d.fillRect(100,0,300,50);
g2d.setColor(new Color(r7, 0, b7));
g2d.fillRect(100,150,300,50);
//30000 rectangles
int i;
int j;
for(int l=0;l<30000;l++)
{
b[l]=250;
}
for(i=100;i<=390;)
{for(j=50;j<=140;)
{int l=0;
g2d.setColor(new Color(0, 0, b[l]));
g2d.fillRect(i,j,10,10);
j=j+10;
l++;
}
i=i+10;
}
//cylindre
g.setColor(Color.yellow);
g.fillOval(50,75,50,50);
g.setColor(c);
}
} |