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
|
public class VuePiece extends JPanel {
// Déclarer 2 tableaux pour les coordonnées
int x[], y[];
public Polygon polygone;
public VuePiece()
{
Graphics g = getGraphics();
setBackground(Color.gray);
x = new int[8];
y = new int[8];
x[0] = 0; y[0] = 40;
x[1] = 40; y[1] = 0;
x[2] = 80; y[2] = 0;
x[3] = 120; y[3] = 40;
x[4] = 120; y[4] = 80;
x[5] = 80; y[5] = 120;
x[6] = 40; y[6] = 120;
x[7] = 0; y[7] = 80;
polygone = new Polygon(x,y,x.length);
g.setColor(Color.black);
g.drawPolygon(polygone);
}
public void paint(Graphics g)
{
Graphics2D g2 = (Graphics2D) g;
g2.clip(this.polygone);
AffineTransform rotation = new AffineTransform();
rotation.concatenate(AffineTransform.getRotateInstance((Math.PI)/4,60,60));
g2.transform(rotation);
Rectangle rect= new Rectangle(55, -10, 10, 130);
g2.fillRect(rect.x, rect.y, rect.width, rect.height);
g2.dispose();
}
} |
Partager