public class FlyWeightEX
{private static final String colors[] =
{
“Red”, “Green”, “Blue”, “White”, “Black”
};public static void main(String[] args)
{for (int i = 0; i < 10; ++i)
{
String targetColor=getRandomColor();
System.out.println("Target color: "+targetColor);
Circle circle = (Circle) ShapeFactory.getCircle(targetColor);
circle.setX(getRandomX());
circle.setY(getRandomY());
circle.setRadius(50);
circle.draw();
}
}private static String getRandomColor()
{
return colors[(int) (Math.random() * colors.length)];
}private static int getRandomX()
{
return (int) (Math.random() * 100);
}private static int getRandomY()
{
return (int) (Math.random() * 100);
}}
[/code]