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
|
package jeremyravel;
import java.applet.Applet;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Polygon;
import java.util.ArrayList;
public class test extends Applet {
public void paint (Graphics g) {
int a = (int) (Math.random() * 3 + 1 );
switch (a) {
case 1:
drawRect(g);
break;
case 2: drawCircle(g);
break;
case 3: drawPolygone(g);
break;
}
}
public void drawRect(Graphics g)
{
int x= 0 ;
int y = 39;
// Dessiner un rectangle plein (4 point) et de dimensions (22,90).
Polygon rectangle = new Polygon();
rectangle.addPoint(x +396, y+=51); // point haut gauche: x = 148, y = 90
rectangle.addPoint(x +496, y); // point haut droite: x = 170, y = 90
rectangle.addPoint(x +496, y+=60); // point bas droite: x = 170, y = 150
rectangle.addPoint(x +396, y); // point bas gauche: x = 148, y = 150
g.setColor(Color.blue); // fond du rectangle
g.fillPolygon(rectangle); // remplissage
g.drawPolygon(rectangle); // affichage
}
public void drawPolygone(Graphics g)
{
int y = 39;
int x = 0 ;
// Dessiner un triangle plein (3points)
Polygon triangle = new Polygon();
triangle.addPoint(x +446, y+=51); // point haut: x = 446, y = 90
triangle.addPoint(x +496, y+=60); // point bas droite: x = 496, y = 150
triangle.addPoint(x +396, y); // point bas gauche: x = 396, y = 150
g.setColor(Color.RED); // fond du triangle
g.fillPolygon(triangle); // remplissage
g.drawPolygon(triangle); // affichage
}
public void drawCircle(Graphics g)
{
int x = 0;
int y = 39;
// Dessiner un ovale plein .
// dans ce cas l'ovale est un cercle (dim. 50X50)
g.setColor(Color.GREEN); // couleur de remplissage (fond)
g.fillOval(x +450, y+=61, 50, 50); // remplissage (fill)
g.drawOval(x +450, y, 50, 50); // affichage, dessiner (draw)
}
public static void main(String[] args)
{
new test();
}
} |
Partager