Java Reference
In-Depth Information
**15.13
(
Geometry: inside a rectangle?
) Write a program that draws a fixed rectangle
centered at (
100
,
60
) with width
100
and height
40
. Whenever the mouse is
moved, display a message indicating whether the mouse point is inside the rec-
tangle at the mouse point or outside of it, as shown in Figure 15.27b. To detect
whether a point is inside a polygon, use the
contains
method defined in the
Node
class.
**15.14
(
Geometry: inside a polygon?
) Write a program that draws a fixed polygon
with points at (
40
,
20
), (
70
,
40
), (
60
,
80
), (
45
,
45
), and (
20
,
60
). When-
ever the mouse is moved, display a message indicating whether the mouse
point is inside the polygon at the mouse point or outside of it, as shown in
Figure 15.27c. To detect whether a point is inside a polygon, use the
contains
method defined in the
Node
class.
**15.15
(
Geometry: add and remove points
) Write a program that lets the user click on
a pane to dynamically create and remove points (see Figure 15.28a). When the
user left-clicks the mouse (primary button), a point is created and displayed
at the mouse point. The user can remove a point by pointing to it and right-
clicking the mouse (secondary button).
F
IGURE
15.28
(a) Exercise 15.15 allows the user to create/remove points dynamically.
(b) Exercise 15.16 displays two vertices and a connecting edge.
*15.16
(
Two movable vertices and their distances
) Write a program that displays two
circles with radius
10
at location (
40
,
40
) and (
120
,
150
) with a line connect-
ing the two circles, as shown in Figure 15.28b. The distance between the circles
is displayed along the line. The user can drag a circle. When that happens, the
circle and its line are moved and the distance between the circles is updated.
**15.17
(
Geometry: find the bounding rectangle
) Write a program that enables the user
to add and remove points in a two-dimensional plane dynamically, as shown
in Figure 15.29a. A minimum bounding rectangle is updated as the points are
added and removed. Assume that the radius of each point is
10
pixels.
(a)
(b)
(c)
F
IGURE
15.29
(a) Exercise 15.17 enables the user to add/remove points dynamically and displays the bounding
rectangle. (b) When you click a circle, a new circle is displayed at a random location. (c) After 20 circles are clicked, the
time spent is displayed in the pane.
Search WWH ::
Custom Search