Java Reference
In-Depth Information
Hint :
, use
g.drawString("-2\u03c0", x, y) . For a trigonometric function like
sin(x) , x is in radians. Use the following loop to add the points to a polygon p :
The Unicode for
π
is \u03c0 . To display
2
π
for ( int x = -170 ; x <= 170 ; x++) {
p.addPoint(x + 200 ,
100 - ( int )( 50 * Math.sin((x / 100.0 ) * 2 * Math.PI)));
}
is at ( 300 ,
100 ). Use the drawPolyline method in the Graphics class to connect the
points.
**13.13 ( Paint a smiley face ) Write a program that paints a smiley face, as shown in
Figure 13.30b.
2
π
is at ( 100 , 100 ), the center of the axis is at ( 200 , 100 ), and 2
π
(a)
(b)
F IGURE 13.30
(a) Exercise 13.12 plots the sine/cosine functions. (b) Exercise 13.13 paints a
smiley face.
**13.14
( Display a bar chart ) Write a program that uses a bar chart to display the percent-
ages of the overall grade represented by projects, quizzes, midterm exams, and the
final exam, as shown in Figure 13.1a. Suppose that projects take 20 percent and
are displayed in red, quizzes take 10 percent and are displayed in blue, midterm
exams take 30 percent and are displayed in green, and the final exam takes 40 per-
cent and is displayed in orange.
**13.15
( Display a pie chart ) Write a program that uses a pie chart to display the percent-
ages of the overall grade represented by projects, quizzes, midterm exams, and the
final exam, as shown in Figure 13.31a. Suppose that projects take 20 percent and
are displayed in red, quizzes take 10 percent and are displayed in blue, midterm
exams take 30 percent and are displayed in green, and the final exam takes 40 per-
cent and is displayed in orange.
VideoNote
Plot a bar chart
13.16
( Obtain font information ) Write a program that displays the message Java is fun
in a panel. Set the panel's font to TimesRoman , bold , and 20 pixel. Display
the font's leading, ascent, descent, height, and the string width as a tool tip text for
the panel, as shown in Figure 13.31b.
13.17
( Game: hangman ) Write a program that displays a drawing for the popular hang-
man game, as shown in Figure 13.31c.
 
Search WWH ::




Custom Search