Java Reference
In-Depth Information
Use text fields for the investment amount, number of years, and annual interest
rate. Display the future amount in a text field when the user clicks the Calculate
button, as shown in Figure 15.25b.
Sections 15.8 and 15.9
**15.6
( Alternate two messages ) Write a program to display the text Java is fun
and Java is powerful alternately with a mouse click.
*15.7
( Change color using a mouse ) Write a program that displays the color of a
circle as black when the mouse button is pressed and as white when the mouse
button is released.
*15.8
( Display the mouse position ) Write two programs, such that one displays the
mouse position when the mouse button is clicked (see Figure 15.26a) and the
other displays the mouse position when the mouse button is pressed and ceases
to display it when the mouse button is released.
(a)
(b)
F IGURE 15.26
(a) Exercise 15.8 displays the mouse position. (b) Exercise 15.9 uses the
arrow keys to draw the lines.
*15.9
( Draw lines using the arrow keys ) Write a program that draws line segments
using the arrow keys. The line starts from the center of the pane and draws
toward east, north, west, or south when the right-arrow key, up-arrow key, left-
arrow key, or down-arrow key is pressed, as shown in Figure 15.26b.
**15.10
( Enter and display a string ) Write a program that receives a string from the
keyboard and displays it on a pane. The Enter key signals the end of a string.
Whenever a new string is entered, it is displayed on the pane.
*15.11
( Move a circle using keys ) Write a program that moves a circle up, down, left,
or right using the arrow keys.
**15.12
( Geometry: inside a circle? ) Write a program that draws a fixed circle centered
at ( 100 , 60 ) with radius 50 . Whenever the mouse is moved, display a message
indicating whether the mouse point is inside the circle at the mouse point or
outside of it, as shown in Figure 15.27a.
VideoNote
Check mouse point location
(a)
(b)
(c)
F IGURE 15.27
Detect whether a point is inside a circle, a rectangle, or a polygon.
 
Search WWH ::




Custom Search