I have a drawShapeAt
method in a class that should print a shape at a given location
@Override
public void drawShapeAt(int x, int y) {
try {
canvas.removeMouseListener(ml);
} catch (Exception e) {
}
polygon = new RegularPolygon(x, y, Integer.parseInt(polygonRadius), Integer.parseInt(polygonLines));
BufferedImage image = new BufferedImage(800, 600, BufferedImage.TYPE_INT_ARGB);
Graphics2D graphics = image.createGraphics();
Random rand = new Random();
graphics.setColor(new Color(rand.nextInt(0xFFFFFF)));
graphics.fill(polygon);
System.out.println("Painting polygon..");
canvas.paintComponents(graphics);
}
}
If I write for example canvas.setBackground
it will change the background, yet it will not print the shape. My RegularPolygon is as follows:
public class RegularPolygon extends Polygon {
public RegularPolygon(int x0, int y0, int radius, int sides) {
double alpha = 2 * Math.PI / sides;
for (int i = 0; i < sides; i++) {
double x = x0 + radius * Math.cos(alpha * i);
double y = y0 + radius * Math.sin(alpha * i);
this.addPoint((int) x, (int) y);
}
}
}
I checked for wrong variables, but all are ok (x,y, polygonRadius, polygonLines).