Java Reference
In-Depth Information
GradientPaint(float x1, float y1,Color c1, float x2, float y2,Color c2, boolean
This is the same as the previous constructor except for the explicit point coordinates.
Points that are off the line defining the color gradient have the same color as the normal (that is, right-
angle) projection of the point onto the line. This stuff is easier to demonstrate than to describe, so Figure
19-20 shows the output from the example you're going to try out next.
FIGURE 19-20
You can see that points along lines at right angles to the line defined by p1 and p2 have the same color as
the point on the line. The window shows both cyclic and acyclic gradient fill.
TRY IT OUT: Color Gradients
You will create an example similar to the star applet except that the applet draws rectangles with Gradi-
entPaint fills. Here's the complete code:
import javax.swing.*;
import java.awt.*;
import java.awt.geom.*;
public class GradientApplet extends JApplet {
// Initialize the applet
public void init() {
GradientPane pane = new GradientPane(); // Pane contains filled
Search WWH ::

Custom Search