Java Reference
In-Depth Information
(a)
(b)
(c)
F IGURE 13.28 (a) Four panels of geometric figures are displayed in a frame of GridLayout . (b) TicTacToe cells ran-
domly display X, O, or nothing. (c) Exercise 13.8 draws an octagon.
*13.9 ( Create four fans ) Write a program that places four fans in a frame of
GridLayout with two rows and two columns, as shown in Figure 13.29a.
*13.10 ( Display a cylinder ) Write a program that draws a cylinder, as shown in Figure 13.29b.
(a)
(b)
(c)
F IGURE 13.29 (a) Exercise 13.9 draws four fans. (b) Exercise 13.10 draws a cylinder. (c) Exercise 13.11 draws a dia-
gram for function f ( x )
x 2 .
=
*13.11
( Plot the square function ) Write a program that draws a diagram for the function
(see Figure 13.29c).
Hint : Add points to a polygon p using the following loop:
x 2
f ( x )
=
double scaleFactor = 0.1 ;
for ( int x = -100 ; x <= 100 ; x++) {
p.addPoint(x + 200 , 200 - ( int )(scaleFactor * x * x));
}
Connect the points using g.drawPolyline(p.xpoints, p.ypoints,
p.npoints) for a Graphics object g . p.xpoints returns an array of x -
coordinates, p.ypoints an array of y -coordinates, and p.npoints the number
of points in Polygon object p .
**13.12 ( Plot the sine and cosine functions ) Write a program that plots the sine function in
red and cosine in blue, as shown in Figure 13.30a.
VideoNote
Plot a function
 
 
Search WWH ::




Custom Search