Web hosting support - Chapter 11 Graphics and Java2D 621 48 //
Chapter 11 Graphics and Java2D 621 48 // execute application 49 public static void main( String args[] ) 50 { 51 LinesRectsOvals application = new LinesRectsOvals(); 52 53 application.setDefaultCloseOperation( 54 JFrame.EXIT_ON_CLOSE ); 55 } 56 57 } // end class LinesRectsOvals drawRect drawLine fillRect draw3DRect fill3DRect fillRoundRect drawRoundRect drawOval fillOval Fig. 11.14 Demonstrating Graphicsmethod drawLine(part 2 of 2). Methods fillRoundRect (line 36) and drawRoundRect (line 37) draw rectangles with rounded corners. Their first two arguments specify the coordinates of the upper- left corner of the bounding rectangle the area in which the rounded rectangle will be drawn. Note that the upper-left corner coordinates are not the edge of the rounded rectangle, but the coordinates where the edge would be if the rectangle had square corners. The third and fourth arguments specify the widthand heightof the rectangle. Their last two arguments arcWidthand arcHeight determine the horizontal and vertical diameters of the arcs used to represent the corners. Methods draw3DRect (line 40) and fill3DRect (line 41) take the same arguments. The first two arguments specify the top-left corner of the rectangle. The next two arguments specify the width and height of the rectangle, respectively. The last argument determines whether the rectangle is raised (true) or lowered (false). The three- dimensional effect of draw3DRectappears as two edges of the rectangle in the original color and two edges in a slightly darker color. The three-dimensional effect of fill3DRectappears as two edges of the rectangle in the original drawing color and the fill and other two edges in a slightly darker color. Raised rectangles have the original drawing color edges at the top and left of the rectangle. Lowered rectangles have the original drawing color edges at the bottom and right of the rectangle. The three-dimensional effect is difficult to see in some colors. Figure 11.15 labels the arc width, arc height, width and height of a rounded rectangle. Using the same value for arcWidth and arcHeightproduces a quarter circle at each corner. When width, height, arcWidthand arcHeighthave the same values, the result is a circle. If the values for widthand heightare the same and the values of arc- Widthand arcHeightare 0, the result is a square. Copyright 1992 2002 by Deitel & Associates, Inc. All Rights Reserved. 7/7/01