# Make a polygon appear in random places using Japplet and Canvas

• February 23rd, 2013, 04:57 PM
DANGEROUSSCION
Make a polygon appear in random places using Japplet and Canvas
I can make the circles appear in random places, but need a little direction to make the polygon appear in random places.

Code Java:

```import java.awt.*;   public class Circle { private int number; private int diameter; private Color colour;   public Circle(int num) { number = num; diameter = randomInt(20, 50); colour = new Color(randomInt(0, 255),randomInt(0, 255),randomInt(0, 255)); }   public int getDiameter() { return diameter; }   private int randomInt(int min, int max) { return (int)(Math.random() * (max - min + 1) + min); }   public void display(Graphics g, int x, int y) { int radius = diameter / 2;   //THE POLYGON IS SET IN ONE PLACE int[] polyx = {6, 59, 84, 126, 151, 194, 194, 6}; int[] polyy = {47, 47, 27, 27, 47, 47, 77, 77}; g.setColor(colour); g.fillPolygon(polyx, polyy, 8);   //THE CIRCLES ARE DRAWN IN RANDOM PLACES g.setColor(colour); g.fillOval(x, y, diameter, diameter); g.setColor(Color.BLACK); g.drawOval(x, y, diameter, diameter); g.drawString("" + number, x + radius, y + radius); } } { }```
• February 23rd, 2013, 05:35 PM
Norm
Re: Make a polygon appear in random places using Japplet and Canvas
Do you want the shape to stay the same and only the location to move?
Chose a new x,y location and add the new values to all the x and y values that define the polygon.
• February 23rd, 2013, 05:37 PM
DANGEROUSSCION
Re: Make a polygon appear in random places using Japplet and Canvas
the polygon is a car shape, and I've got to make 10 cars appear randomly in the applet. So everytime the Applet is run they all appear in different places.
• February 23rd, 2013, 06:43 PM
Norm
Re: Make a polygon appear in random places using Japplet and Canvas
Have you tried what I suggested? What happened?