15.5 Drawing Lines, Rectangles and Ovals
This section presents Graphics methods for drawing lines, rectangles and ovals. The methods and their parameters are summarized in Fig. 15.17. 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.
Fig. 15.17 Graphics
methods that draw lines, rectangles and ovals.
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 width and height. The rectangle’s top-lef corner is located at (x, y). Only the outline ... |
Get Java How to Program (early objects), 9/e now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.