4.docx

4. [P4_BoxClick] You are to write a graphical program that tracks if a user clicks inside or outside of a box. In the image below you will notice two blue boxes and many circles. Notice that the blue circles are inside the boxes, and the red circles are outside the boxes.

p4

 

Your goal is to complete the P4_BoxClick class such that it:

1. draws two boxes (i.e., rectangles)

2. draws a circle where a user clicks on the panel

3. colors the circle blue if the click is inside one of the boxes, or red if it the click is outside one of the boxes

In the P4_BoxClick class I have provided you with a few things:

· The main method creates a DrawingPanel object that is 400 pixels wide by 400 pixels high

· It creates a mouse click handler for which you do not need to worry about the mechanics, all you need to know is that when the mouse is clicked on the panel it will call the `handleMouseClick` method that I provided.

· The `handleMouseClick` method has three parameters: the graphics context object, an x coordinate, and a y coordinate that correspond to the (x, y) location where the user clicked

The location and size of the boxes are up to you, but they must have a minimum width and height of 20 pixels. The circles for the clicks should have a diameter of at least 3 pixels and be drawn centered on the (x, y) coordinate on which the user clicked.

You should not modify the signature of the `handleMouseClick` method. This can lead to a few magic numbers in your solution, but that's okay for this problem. 

Where I can do them in Eclipse: