Free web space - 618 Graphics and Java2D Chapter 11 51 52535455

618 Graphics and Java2D Chapter 11 51 52535455 56 } application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); } // end class Metrics Fig. 11.12 Fig. 11.12 Obtaining font metric information (part 2 of 2). Line 29 creates and sets the current drawing font to a SansSerif, bold, 12-point font. Line 30 uses Graphicsmethod getFontMetricsto obtain the FontMetrics object for the current font. Line 31 uses an implicit call to class Font s toString method to output the string representation of the font. Lines 32 35 use FontMetric methods to obtain the ascent, descent, height and leading for the font. Line 37 creates a new Serif, italic, 14-point font. Line 38 uses a second version of Graphicsmethod getFontMetrics, which receives a Fontargument and returns a corresponding FontMetricsobject. Lines 41 44 obtain the ascent, descent, height and leading for the font. Notice that the font metrics are slightly different for the two fonts. 11.5 Drawing Lines, Rectangles and Ovals This section presents a variety of Graphics methods for drawing lines, rectangles and ovals. The methods and their parameters are summarized in Fig. 11.13. For each drawing method that requires a width and height parameter, the width and height must be nonnegative values. Otherwise, the shape will not display.. Method Description public void drawLine( int x1, int y1, int x2, int y2 ) Draws a line between the point (x1, y1) and the point (x2, y2). public void drawRect( int x, int y, int width, int height ) Draws a rectangle of the specified widthand height. The top- left corner of the rectangle has the coordinates (x, y). Fig. 11.13 Graphicsmethods that draw lines, rectangles and ovals (part 1 of 2). Copyright 1992 2002 by Deitel & Associates, Inc. All Rights Reserved. 7/7/01

Leave a Reply