Java Reference
In-Depth Information
java.awt.Graphics
+setColor(color: Color): void
+setFont(font: Font): void
+drawString(s: String, x: int, y: int): void
+drawLine(x1: int, y1: int, x2: int, y2:
int): void
+drawRect(x: int, y: int, w: int, h: int):
void
+fillRect(x: int, y: int, w: int, h: int): void
Sets a new color for subsequent drawings.
Sets a new font for subsequent drawings.
Draws a string starting at point (x, y) .
Draws a line from (x1, y1) to (x2, y2) .
Draws a rectangle with specified upper-left corner point at
(x,y) and width w and height h .
Draws a filled rectangle with specified upper-left corner point
at (x, y) and width w and height h .
Draws a round-cornered rectangle with specified arc width
aw and arc height ah .
Draws a filled round-cornered rectangle with specified arc
width aw and arc height ah .
Draws a 3-D rectangle raised above the surface or sunk into
the surface.
Draws a filled 3-D rectangle raised above the surface or sunk
into the surface.
Draws an oval bounded by the rectangle specified by the
parameters x , y , w , and h .
Draws a filled oval bounded by the rectangle specified by the
parameters x , y , w , and h .
Draws an arc conceived as part of an oval bounded by the
rectangle specified by the parameters x , y , w , and h .
Draws a filled arc conceived as part of an oval bounded by the
rectangle specified by the parameters x , y , w , and h .
Draws a closed polygon defined by arrays of x - and
y -coordinates. Each pair of (x[i], y[i]) -coordinates is a point.
Draws a filled polygon defined by arrays of x - and
y -coordinates. Each pair of (x[i], y[i]) -coordinates is a point.
Draws a closed polygon defined by a Polygon object.
Draws a filled polygon defined by a Polygon object.
Draws a polyline defined by arrays of x - and y -coordinates.
Each pair of (x[i], y[i]) -coordinates is a point.
+drawRoundRect(x: int, y: int, w: int, h: int, aw:
int, ah: int): void
+fillRoundRect(x: int, y: int, w: int, h: int,
aw: int, ah: int): void
+draw3DRect(x: int, y: int, w: int, h: int,
raised: boolean): void
+fill3DRect(x: int, y: int, w: int, h: int,
raised: boolean): void
+drawOval(x: int, y: int, w: int, h: int):
void
+fillOval(x: int, y: int, w: int, h: int): void
+drawArc(x: int, y: int, w: int, h: int,
startAngle: int, arcAngle: int): void
+fillArc(x: int, y: int, w: int, h: int,
startAngle: int, arcAngle: int): void
+drawPolygon(xPoints: int[], yPoints:
int[], nPoints: int): void
+fillPolygon(xPoints: int[], yPoints: int[],
nPoints: int): void
+drawPolygon(g: Polygon): void
+fillPolygon(g: Polygon): void
+drawPolyline(xPoints: int[], yPoints:
int[], nPoints: int): void
F IGURE 13.2
The Graphics class contains the methods for drawing strings and shapes.
x
Y axis
(0, 0)
X axis
y
( x , y )
(0, 0)
X axis
Conventional
Coordinate
System
Java Coordinate
System
Y axis
F IGURE 13.3
The Java coordinate system is measured in pixels, with (0, 0) at its upper-
left corner.
L ISTING 13.1 TestPaintComponent.java
1 import javax.swing.*;
2 import java.awt.Graphics;
3
 
 
Search WWH ::




Custom Search