- java.lang.Object
- 
- java.awt.GradientPaint
 
- 
- All Implemented Interfaces:
- Paint,- Transparency
 
 public class GradientPaint extends Object implements Paint TheGradientPaintclass provides a way to fill aShapewith a linear color gradient pattern. IfPointP1 withColorC1 andPointP2 withColorC2 are specified in user space, theColoron the P1, P2 connecting line is proportionally changed from C1 to C2. Any point P not on the extended P1, P2 connecting line has the color of the point P' that is the perpendicular projection of P on the extended P1, P2 connecting line. Points on the extended line outside of the P1, P2 segment can be colored in one of two ways.- If the gradient is cyclic then the points on the extended P1, P2 connecting line cycle back and forth between the colors C1 and C2.
- 
 If the gradient is acyclic then points on the P1 side of the segment
 have the constant ColorC1 while points on the P2 side have the constantColorC2.
 - See Also:
- Paint,- Graphics2D.setPaint(java.awt.Paint)
 
- 
- 
Field Summary- 
Fields declared in interface java.awt.TransparencyBITMASK, OPAQUE, TRANSLUCENT
 
- 
 - 
Constructor SummaryConstructors Constructor Description GradientPaint(float x1, float y1, Color color1, float x2, float y2, Color color2)Constructs a simple acyclicGradientPaintobject.GradientPaint(float x1, float y1, Color color1, float x2, float y2, Color color2, boolean cyclic)Constructs either a cyclic or acyclicGradientPaintobject depending on thebooleanparameter.GradientPaint(Point2D pt1, Color color1, Point2D pt2, Color color2)Constructs a simple acyclicGradientPaintobject.GradientPaint(Point2D pt1, Color color1, Point2D pt2, Color color2, boolean cyclic)Constructs either a cyclic or acyclicGradientPaintobject depending on thebooleanparameter.
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description PaintContextcreateContext(ColorModel cm, Rectangle deviceBounds, Rectangle2D userBounds, AffineTransform xform, RenderingHints hints)Creates and returns aPaintContextused to generate a linear color gradient pattern.ColorgetColor1()Returns the color C1 anchored by the point P1.ColorgetColor2()Returns the color C2 anchored by the point P2.Point2DgetPoint1()Returns a copy of the point P1 that anchors the first color.Point2DgetPoint2()Returns a copy of the point P2 which anchors the second color.intgetTransparency()Returns the transparency mode for thisGradientPaint.booleanisCyclic()Returnstrueif the gradient cycles repeatedly between the two colors C1 and C2.
 
- 
- 
- 
Constructor Detail- 
GradientPaintpublic GradientPaint(float x1, float y1, Color color1, float x2, float y2, Color color2)Constructs a simple acyclicGradientPaintobject.- Parameters:
- x1- x coordinate of the first specified- Pointin user space
- y1- y coordinate of the first specified- Pointin user space
- color1-- Colorat the first specified- Point
- x2- x coordinate of the second specified- Pointin user space
- y2- y coordinate of the second specified- Pointin user space
- color2-- Colorat the second specified- Point
- Throws:
- NullPointerException- if either one of colors is null
 
 - 
GradientPaintpublic GradientPaint(Point2D pt1, Color color1, Point2D pt2, Color color2) Constructs a simple acyclicGradientPaintobject.- Parameters:
- pt1- the first specified- Pointin user space
- color1-- Colorat the first specified- Point
- pt2- the second specified- Pointin user space
- color2-- Colorat the second specified- Point
- Throws:
- NullPointerException- if either one of colors or points is null
 
 - 
GradientPaintpublic GradientPaint(float x1, float y1, Color color1, float x2, float y2, Color color2, boolean cyclic)Constructs either a cyclic or acyclicGradientPaintobject depending on thebooleanparameter.- Parameters:
- x1- x coordinate of the first specified- Pointin user space
- y1- y coordinate of the first specified- Pointin user space
- color1-- Colorat the first specified- Point
- x2- x coordinate of the second specified- Pointin user space
- y2- y coordinate of the second specified- Pointin user space
- color2-- Colorat the second specified- Point
- cyclic-- trueif the gradient pattern should cycle repeatedly between the two colors;- falseotherwise
 
 - 
GradientPaint@ConstructorProperties({"point1","color1","point2","color2","cyclic"}) public GradientPaint(Point2D pt1, Color color1, Point2D pt2, Color color2, boolean cyclic) Constructs either a cyclic or acyclicGradientPaintobject depending on thebooleanparameter.- Parameters:
- pt1- the first specified- Pointin user space
- color1-- Colorat the first specified- Point
- pt2- the second specified- Pointin user space
- color2-- Colorat the second specified- Point
- cyclic-- trueif the gradient pattern should cycle repeatedly between the two colors;- falseotherwise
- Throws:
- NullPointerException- if either one of colors or points is null
 
 
- 
 - 
Method Detail- 
getPoint1public Point2D getPoint1() Returns a copy of the point P1 that anchors the first color.- Returns:
- a Point2Dobject that is a copy of the point that anchors the first color of thisGradientPaint.
 
 - 
getColor1public Color getColor1() Returns the color C1 anchored by the point P1.- Returns:
- a Colorobject that is the color anchored by P1.
 
 - 
getPoint2public Point2D getPoint2() Returns a copy of the point P2 which anchors the second color.- Returns:
- a Point2Dobject that is a copy of the point that anchors the second color of thisGradientPaint.
 
 - 
getColor2public Color getColor2() Returns the color C2 anchored by the point P2.- Returns:
- a Colorobject that is the color anchored by P2.
 
 - 
isCyclicpublic boolean isCyclic() Returnstrueif the gradient cycles repeatedly between the two colors C1 and C2.- Returns:
- trueif the gradient cycles repeatedly between the two colors;- falseotherwise.
 
 - 
createContextpublic PaintContext createContext(ColorModel cm, Rectangle deviceBounds, Rectangle2D userBounds, AffineTransform xform, RenderingHints hints) Creates and returns aPaintContextused to generate a linear color gradient pattern. See thespecificationof the method in thePaintinterface for information on null parameter handling.- Specified by:
- createContextin interface- Paint
- Parameters:
- cm- the preferred- ColorModelwhich represents the most convenient format for the caller to receive the pixel data, or- nullif there is no preference.
- deviceBounds- the device space bounding box of the graphics primitive being rendered.
- userBounds- the user space bounding box of the graphics primitive being rendered.
- xform- the- AffineTransformfrom user space into device space.
- hints- the set of hints that the context object can use to choose between rendering alternatives.
- Returns:
- the PaintContextfor generating color patterns.
- See Also:
- Paint,- PaintContext,- ColorModel,- Rectangle,- Rectangle2D,- AffineTransform,- RenderingHints
 
 - 
getTransparencypublic int getTransparency() Returns the transparency mode for thisGradientPaint.- Specified by:
- getTransparencyin interface- Transparency
- Returns:
- an integer value representing this GradientPaintobject's transparency mode.
- See Also:
- Transparency
 
 
- 
 
-