Java Reference
In-Depth Information
FIGURE 13.4
Two rectangles
using the same
GradientPaint
.
If you want to use a cyclic gradient shift, an extra argument is added at the end:
GradientPaint gp = new GradientPaint(
x1, y1, color1, x2, y2, color2, true);
The last argument is a Boolean value that is
true
for a cyclic shift. A
false
argument
can be used for acyclic shifts, or you can omit this argument; acyclic shifts are the
default behavior.
After you have created a
GradientPaint
object, set it as the current paint attribute by
using the
setPaint()
method. The following statements create and select a gradient:
GradientPaint pat = new GradientPaint(0f,0f,Color.white,
100f,45f,Color.blue);
comp2D.setPaint(pat);
All subsequent drawing operations to the
comp2D
object use this fill pattern until another
one is chosen.
Setting a Drawing Stroke
Java2D offers the capability to vary the width of drawn lines by using the
setStroke()
method with a
BasicStroke
.
A simple
BasicStroke
constructor takes three arguments:
A
float
value representing the line width, with
1.0
as the norm
n
An
int
value determining the style of cap decoration drawn at the end of a line
n
An
int
value determining the style of juncture between two line segments
n