Java Reference
In-Depth Information
7
public static void main(String[] args)
8
{
9
DrawRainbow panel = new DrawRainbow();
10
JFrame application = new JFrame();
11
12
application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
13
application.add(panel);
14
application.setSize( 400 , 250 );
15
application.setVisible( true );
16
}
17
} // end class DrawRainbowTest
Fig. 7.26 | Test application to display a rainbow. (Part 2 of 2.)
GUI and Graphics Case Study Exercise
7.1
(Drawing Spirals) In this exercise, you'll draw spirals with methods drawLine and drawArc .
a)
Draw a square-shaped spiral (as in the left screen capture of Fig. 7.27), centered on the
panel, using method drawLine . One technique is to use a loop that increases the line
length after drawing every second line. The direction in which to draw the next line
should follow a distinct pattern, such as down, left, up, right.
b)
Draw a circular spiral (as in the right screen capture of Fig. 7.27), using method
drawArc to draw one semicircle at a time. Each successive semicircle should have a larger
radius (as specified by the bounding rectangle's width) and should continue drawing
where the previous semicircle finished.
Fig. 7.27 | Drawing a spiral using drawLine (left) and drawArc (right).
Search WWH ::




Custom Search