import java.util.Random; /** * Draws random squares */ public class RandomSquares { public static void main(String[] args) { final int MAX_X = 200; final int MAX_Y = 300; final int LENGTH = 20; final int NUMBERSLENGTHCANBE = 80; Random gen = new Random(987456789); boolean first = true; int greatestLength = 0; Rectangle largestRectangle= null; for (int i = 1; i <26; i++) { int x = gen.nextInt(MAX_X); int y = gen.nextInt(MAX_Y); int length = gen.nextInt(NUMBERSLENGTHCANBE) + LENGTH;//20<x<100 Rectangle rectangle = new Rectangle(x,y,length,length); if(length>greatestLength) { greatestLength = length; rectangle = new Rectangle(x,y,greatestLength,greatestLength); largestRectangle = rectangle; } rectangle.draw(); rectangle.setColor(Color.GREEN); } largestRectangle.setColor(Color.BLUE); largestRectangle.fill(); } }