Lab 7 Mouse Clicks
Task 1, Getting the Mouse Clicks
Write a program that
- Opens a graphics window
- Prints a message at the top telling the user to click on three points.
- Draws a small red circle at each point.
- Prints a message at the bottom telling the user to click when done
- Closes the graphics window
Task 2, Custom Circles
Write a modified program that allows the user to specifiy the radii of the circles:
- Opens a graphics window
- Prints a message at the top telling the user to click on three pairs of points.
- Draws a small red circle at the first point of each pair.
- When the user clicks on the second point of a pair replace the
just drawn circle with one with the same center as before, but this
time containing the point just clicked. That means use the second
point to determine a new radius, the distance from the center to this
point. The book has had problems about the distance between two
points. This time it is complicated by the fact that the
coordinates are recovered with the getX and getY methods. For
example, if the two points are named p1 and p2, the distance
between them is
math.sqrt((p1.getX() - p2.getX())**2 + (p1.getY() - p2.getY())**2)
Before drawing the new circle, be sure to undraw the old one.
- Prints a message at the bottom telling the user to click when done
- Closes the graphics window
An alternative, if you prefer, is to just draw a point at the first click in a pair, and only draw a circle on the second click.
Show a TA or pass in your Task 2 if requested instead.