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
| import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.*;
import java.util.Random;
@SuppressWarnings("serial")
public class Cases extends JPanel {
{
final BufferedImage image =
new BufferedImage(706, 750, BufferedImage.TYPE_INT_RGB);
Graphics g = (Graphics)image.getGraphics();
int x1=0,y1=0,x4=0,y4=0,x5=0;
while (x1<=1000) {
g.drawLine(x1, 0, x1, 600);
x1+=25;
}
while (y1<=600) {
g.drawLine(0, y1, 707, y1);
y1+=25;
}
while (x5<=1000) {
paintAleat(g, x4, y4, 24, 24);
x4+=25;
x5+=25;
}
@Override
public void paintComponent(Graphics g) {
g.drawImage(image, 0, 0, null);
}
}
public static void paintAleat(Graphics g, int x2, int y2, int x3, int y3) {
while (y2<600) {
Random r = new Random();
int valeurMin = 1, valeurMax = 6;
int nr = valeurMin + r.nextInt(valeurMax - valeurMin);
if (nr==1) {
g.setColor(Color.blue);
}
if (nr==2) {
g.setColor(Color.red);
}
if (nr==3) {
g.setColor(Color.yellow);
}
if (nr==4) {
g.setColor(Color.green);
}
if (nr==5) {
g.setColor(new Color( 213, 128, 0));
}
g.drawRect(x2, y2, x3, y3);
g.fillRect(x2, y2, x3, y3);
y2+=25;
}
}
} |
Partager