OverlapCircles - int x = gen.nextInt(WIDTH-2*radius) +...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
//******************************************************************** // OverlapCircles.java Author: Lewis/Loftus // // Solution to Programming Project 6.22 //******************************************************************** / import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.util.Random; i public class OverlapCircles extends JApplet { Circle[] circles; private final int NUM_CIRCLES = 20; private final int MAX_RADIUS = 30; private final int WIDTH = 400, HEIGHT = 400; public void init() { circles = new Circle[NUM_CIRCLES]; Random gen = new Random(); for (int i=0; i<NUM_CIRCLES; i++) { int radius = gen.nextInt(MAX_RADIUS) + 6;
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: int x = gen.nextInt(WIDTH-2*radius) + radius; int y = gen.nextInt(HEIGHT-2*radius) + radius; circles[i] = new Circle(x, y, radius); // check for overlap with previous circles boolean overlap = false; for (int previous = 0; previous &lt; i; previous ++) { if (circles[previous].overlap(circles[i])) { circles[previous].setColor(Color.cyan); overlap = true; } } if (overlap) circles[i].setColor(Color.cyan); } setBackground(Color.white); } public void paint(Graphics page) { for (int i = 0; i&lt;circles.length; i++) circles[i].draw(page); } }...
View Full Document

This note was uploaded on 05/17/2011 for the course COP 3530 taught by Professor Davis during the Spring '08 term at University of Florida.

Ask a homework question - tutors are online