import java.awt.Frame; import java.awt.Color; BouncingWindow w[]; void setup() { w = new BouncingWindow[8]; for (int i = 0; i < w.length; i++) w[i] = new BouncingWindow(); } void draw() { frame.setVisible(false); for (int i = 0; i < w.length; i++) w[i].draw(); } class BouncingWindow { Frame frame; final static int SIZE = 20; float x, y; float vx, vy; BouncingWindow() { x = random(0, screen.width - SIZE); y = random(0, screen.height - SIZE); vx = random(-20, 20); vy = random(-20, 20); frame = new Frame(); frame.setSize(SIZE, SIZE); frame.setLocation(floor(x), floor(y)); frame.setUndecorated(true); frame.setAlwaysOnTop(true); frame.setBackground(new Color(random(1), random(1), 1)); frame.setVisible(true); } void draw() { x += vx; y += vy; if (x < 0) { x = 0; vx *= -1; } if (x > screen.width - SIZE) { x = screen.width - SIZE; vx *= -1; } if (y < 0) { y = 0; vy *= -1; } if (y > screen.height - SIZE) { y = screen.height - SIZE; vy *= -1; } frame.setLocation(floor(x), floor(y)); } }