{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

OverlapCircles

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

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

//******************************************************************** // 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;
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 < 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<circles.length; i++) circles[i].draw(page); } }...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online