// Mark Jacobson - September 12th, 2002 // To be handed out and discussed on Friday, Sept 13th in 810:061 class import objectdraw.*; import java.awt.*; /* program which demonstrates the contains method, as well as demonstrating the objectdraw.jar package RandomIntGenerator class, using the nextValue() method to pick a new randomly chosen color for Humpty. This program could be very useful around Easter time, lol! */ public class OvalContainsPoint extends WindowController { private FilledOval humptyDumpty; private RandomIntGenerator generator; public void begin() { FramedOval humptyFrame; FilledOval humptyMatting; new FilledOval(91, 191, 118, 68, canvas); humptyMatting = new FilledOval(94, 94, 112, 62, canvas); humptyMatting.setColor(Color.red); humptyDumpty = new FilledOval(100, 100, 100, 50, canvas); humptyDumpty.setColor(Color.yellow); humptyFrame = new FramedOval(97, 97, 106, 56, canvas); humptyFrame.setColor(Color.blue); humptyFrame = new FramedOval(98, 98, 104, 54, canvas); humptyFrame.setColor(Color.blue); humptyFrame = new FramedOval(99, 99, 102, 52, canvas); humptyFrame.setColor(Color.blue); generator = new RandomIntGenerator(0, 255); Text t; t = new Text("Click Humpty Dumpty and he will change color", 50, 25, canvas); t.setBold(); t.setColor(Color.blue); new Line(50, 25, 310, 25, canvas); new Line(50, 43, 310, 43, canvas); } public void onMousePress(Location point) { if ( humptyDumpty.contains(point) ) // conditional IF statement { // first example of SELECTION int r, g, b; r = generator.nextValue(); g = generator.nextValue(); b = generator.nextValue(); humptyDumpty.setColor( new Color(r, g, b) ); } } }