Java Reference
In-Depth Information
Positive angles
Negative angles
90º
90º
180º
0º
180º
0º
270º
270º
Fig. 13.22
|
Positive and negative arc angles.
Method
Description
public void
drawArc(
int
x,
int
y,
int
width,
int
height,
int
startAngle,
int
arcAngle)
Draws an arc relative to the bounding rectangle's top-left
x-
and
y-
coordi-
nates with the specified
width
and
height
. The arc segment is drawn starting
at
startAngle
and sweeps
arcAngle
degrees.
public void
fillArc(
int
x,
int
y,
int
width,
int
height,
int
startAngle,
int
arcAngle)
Draws a filled arc (i.e., a sector) relative to the bounding rectangle's top-left
x
- and
y
-coordinates with the specified
width
and
height
. The arc segment
is drawn starting at
startAngle
and sweeps
arcAngle
degrees.
Fig. 13.23
|
Graphics
methods for drawing arcs.
Figures 13.24-13.25 demonstrate the arc methods of Fig. 13.23. The application
draws six arcs (three unfilled and three filled). To illustrate the bounding rectangle that
helps determine where the arc appears, the first three arcs are displayed inside a red rect-
angle that has the same
x
,
y
,
width
and
height
arguments as the arcs.
1
// Fig. 13.24: ArcsJPanel.java
2
// Arcs displayed with drawArc and fillArc.
3
import
java.awt.Color;
4
import
java.awt.Graphics;
5
import
javax.swing.JPanel;
6
7
public
class
ArcsJPanel
extends
JPanel
8
{
9
// draw rectangles and arcs
10
@Override
11
public
void
paintComponent(Graphics g)
12
{
13
super
.paintComponent(g);
14
Fig. 13.24
|
Arcs displayed with
drawArc
and
fillArc
. (Part 1 of 2.)