java.awt
Class GradientPaint

java.lang.Object sample code for java.lang.Object definition code for java.lang.Object 
  extended by java.awt.GradientPaint
All Implemented Interfaces:
Paint sample code for java.awt.Paint definition code for java.awt.Paint , Transparency sample code for java.awt.Transparency definition code for java.awt.Transparency

public class GradientPaint
extends Object sample code for java.lang.Object definition code for java.lang.Object
implements Paint sample code for java.awt.Paint definition code for java.awt.Paint

The GradientPaint class provides a way to fill a Shape sample code for java.awt.Shape definition code for java.awt.Shape with a linear color gradient pattern. If Point sample code for java.awt.Point definition code for java.awt.Point P1 with Color sample code for java.awt.Color definition code for java.awt.Color C1 and Point P2 with Color C2 are specified in user space, the Color on 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.

See Also:
Paint sample code for java.awt.Paint definition code for java.awt.Paint , Graphics2D.setPaint(java.awt.Paint) sample code for java.awt.Graphics2D.setPaint(java.awt.Paint) definition code for java.awt.Graphics2D.setPaint(java.awt.Paint)

Field Summary
 
Fields inherited from interface java.awt.Transparency sample code for java.awt.Transparency definition code for java.awt.Transparency
BITMASK sample code for java.awt.Transparency.BITMASK definition code for java.awt.Transparency.BITMASK , OPAQUE sample code for java.awt.Transparency.OPAQUE definition code for java.awt.Transparency.OPAQUE , TRANSLUCENT sample code for java.awt.Transparency.TRANSLUCENT definition code for java.awt.Transparency.TRANSLUCENT
 
Constructor Summary
GradientPaint sample code for java.awt.GradientPaint.GradientPaint(float, float, java.awt.Color, float, float, java.awt.Color) definition code for java.awt.GradientPaint.GradientPaint(float, float, java.awt.Color, float, float, java.awt.Color) (float x1, float y1, Color sample code for java.awt.Color definition code for java.awt.Color  color1, float x2, float y2, Color sample code for java.awt.Color definition code for java.awt.Color  color2)
          Constructs a simple acyclic GradientPaint object.
GradientPaint sample code for java.awt.GradientPaint.GradientPaint(float, float, java.awt.Color, float, float, java.awt.Color, boolean) definition code for java.awt.GradientPaint.GradientPaint(float, float, java.awt.Color, float, float, java.awt.Color, boolean) (float x1, float y1, Color sample code for java.awt.Color definition code for java.awt.Color  color1, float x2, float y2, Color sample code for java.awt.Color definition code for java.awt.Color  color2, boolean cyclic)
          Constructs either a cyclic or acyclic GradientPaint object depending on the boolean parameter.
GradientPaint sample code for java.awt.GradientPaint.GradientPaint(java.awt.geom.Point2D, java.awt.Color, java.awt.geom.Point2D, java.awt.Color) definition code for java.awt.GradientPaint.GradientPaint(java.awt.geom.Point2D, java.awt.Color, java.awt.geom.Point2D, java.awt.Color) (Point2D sample code for java.awt.geom.Point2D definition code for java.awt.geom.Point2D  pt1, Color sample code for java.awt.Color definition code for java.awt.Color  color1, Point2D sample code for java.awt.geom.Point2D definition code for java.awt.geom.Point2D  pt2, Color sample code for java.awt.Color definition code for java.awt.Color  color2)
          Constructs a simple acyclic GradientPaint object.
GradientPaint sample code for java.awt.GradientPaint.GradientPaint(java.awt.geom.Point2D, java.awt.Color, java.awt.geom.Point2D, java.awt.Color, boolean) definition code for java.awt.GradientPaint.GradientPaint(java.awt.geom.Point2D, java.awt.Color, java.awt.geom.Point2D, java.awt.Color, boolean) (Point2D sample code for java.awt.geom.Point2D definition code for java.awt.geom.Point2D  pt1, Color sample code for java.awt.Color definition code for java.awt.Color  color1, Point2D sample code for java.awt.geom.Point2D definition code for java.awt.geom.Point2D  pt2, Color sample code for java.awt.Color definition code for java.awt.Color  color2, boolean cyclic)
          Constructs either a cyclic or acyclic GradientPaint object depending on the boolean parameter.
 
Method Summary
 PaintContext sample code for java.awt.PaintContext definition code for java.awt.PaintContext createContext sample code for java.awt.GradientPaint.createContext(java.awt.image.ColorModel, java.awt.Rectangle, java.awt.geom.Rectangle2D, java.awt.geom.AffineTransform, java.awt.RenderingHints) definition code for java.awt.GradientPaint.createContext(java.awt.image.ColorModel, java.awt.Rectangle, java.awt.geom.Rectangle2D, java.awt.geom.AffineTransform, java.awt.RenderingHints) (ColorModel sample code for java.awt.image.ColorModel definition code for java.awt.image.ColorModel  cm, Rectangle sample code for java.awt.Rectangle definition code for java.awt.Rectangle  deviceBounds, Rectangle2D sample code for java.awt.geom.Rectangle2D definition code for java.awt.geom.Rectangle2D  userBounds, AffineTransform sample code for java.awt.geom.AffineTransform definition code for java.awt.geom.AffineTransform  xform, RenderingHints sample code for java.awt.RenderingHints definition code for java.awt.RenderingHints  hints)
          Creates and returns a context used to generate the color pattern.
 Color sample code for java.awt.Color definition code for java.awt.Color getColor1 sample code for java.awt.GradientPaint.getColor1() definition code for java.awt.GradientPaint.getColor1() ()
          Returns the color C1 anchored by the point P1.
 Color sample code for java.awt.Color definition code for java.awt.Color getColor2 sample code for java.awt.GradientPaint.getColor2() definition code for java.awt.GradientPaint.getColor2() ()
          Returns the color C2 anchored by the point P2.
 Point2D sample code for java.awt.geom.Point2D definition code for java.awt.geom.Point2D getPoint1 sample code for java.awt.GradientPaint.getPoint1() definition code for java.awt.GradientPaint.getPoint1() ()
          Returns a copy of the point P1 that anchors the first color.
 Point2D sample code for java.awt.geom.Point2D definition code for java.awt.geom.Point2D getPoint2 sample code for java.awt.GradientPaint.getPoint2() definition code for java.awt.GradientPaint.getPoint2() ()
          Returns a copy of the point P2 which anchors the second color.
 int getTransparency sample code for java.awt.GradientPaint.getTransparency() definition code for java.awt.GradientPaint.getTransparency() ()
          Returns the transparency mode for this GradientPaint.
 boolean isCyclic sample code for java.awt.GradientPaint.isCyclic() definition code for java.awt.GradientPaint.isCyclic() ()
          Returns true if the gradient cycles repeatedly between the two colors C1 and C2.
 
Methods inherited from class java.lang.Object sample code for java.lang.Object definition code for java.lang.Object
clone sample code for java.lang.Object.clone() definition code for java.lang.Object.clone() , equals sample code for java.lang.Object.equals(java.lang.Object) definition code for java.lang.Object.equals(java.lang.Object) , finalize sample code for java.lang.Object.finalize() definition code for java.lang.Object.finalize() , getClass sample code for java.lang.Object.getClass() definition code for java.lang.Object.getClass() , hashCode sample code for java.lang.Object.hashCode() definition code for java.lang.Object.hashCode() , notify sample code for java.lang.Object.notify() definition code for java.lang.Object.notify() , notifyAll sample code for java.lang.Object.notifyAll() definition code for java.lang.Object.notifyAll() , toString sample code for java.lang.Object.toString() definition code for java.lang.Object.toString() , wait sample code for java.lang.Object.wait() definition code for java.lang.Object.wait() , wait sample code for java.lang.Object.wait(long) definition code for java.lang.Object.wait(long) , wait sample code for java.lang.Object.wait(long, int) definition code for java.lang.Object.wait(long, int)
 

Constructor Detail

GradientPaint sample code for java.awt.GradientPaint(float, float, java.awt.Color, float, float, java.awt.Color) definition code for java.awt.GradientPaint(float, float, java.awt.Color, float, float, java.awt.Color)

public GradientPaint(float x1,
                     float y1,
                     Color sample code for java.awt.Color definition code for java.awt.Color  color1,
                     float x2,
                     float y2,
                     Color sample code for java.awt.Color definition code for java.awt.Color  color2)
Constructs a simple acyclic GradientPaint object.

Parameters:
x1 - x coordinate of the first specified Point in user space
y1 - y coordinate of the first specified Point in user space
color1 - Color at the first specified Point
x2 - x coordinate of the second specified Point in user space
y2 - y coordinate of the second specified Point in user space
color2 - Color at the second specified Point
Throws:
NullPointerException sample code for java.lang.NullPointerException definition code for java.lang.NullPointerException - if either one of colors is null

GradientPaint sample code for java.awt.GradientPaint(java.awt.geom.Point2D, java.awt.Color, java.awt.geom.Point2D, java.awt.Color) definition code for java.awt.GradientPaint(java.awt.geom.Point2D, java.awt.Color, java.awt.geom.Point2D, java.awt.Color)

public GradientPaint(Point2D sample code for java.awt.geom.Point2D definition code for java.awt.geom.Point2D  pt1,
                     Color sample code for java.awt.Color definition code for java.awt.Color  color1,
                     Point2D sample code for java.awt.geom.Point2D definition code for java.awt.geom.Point2D  pt2,
                     Color sample code for java.awt.Color definition code for java.awt.Color  color2)
Constructs a simple acyclic GradientPaint object.

Parameters:
pt1 - the first specified Point in user space
color1 - Color at the first specified Point
pt2 - the second specified Point in user space
color2 - Color at the second specified Point
Throws:
NullPointerException sample code for java.lang.NullPointerException definition code for java.lang.NullPointerException - if either one of colors or points is null

GradientPaint sample code for java.awt.GradientPaint(float, float, java.awt.Color, float, float, java.awt.Color, boolean) definition code for java.awt.GradientPaint(float, float, java.awt.Color, float, float, java.awt.Color, boolean)

public GradientPaint(float x1,
                     float y1,
                     Color sample code for java.awt.Color definition code for java.awt.Color  color1,
                     float x2,
                     float y2,
                     Color sample code for java.awt.Color definition code for java.awt.Color  color2,
                     boolean cyclic)
Constructs either a cyclic or acyclic GradientPaint object depending on the boolean parameter.

Parameters:
x1 - x coordinate of the first specified Point in user space
y1 - y coordinate of the first specified Point in user space
color1 - Color at the first specified Point
x2 - x coordinate of the second specified Point in user space
y2 - y coordinate of the second specified Point in user space
color2 - Color at the second specified Point
cyclic - true if the gradient pattern should cycle repeatedly between the two colors; false otherwise

GradientPaint sample code for java.awt.GradientPaint(java.awt.geom.Point2D, java.awt.Color, java.awt.geom.Point2D, java.awt.Color, boolean) definition code for java.awt.GradientPaint(java.awt.geom.Point2D, java.awt.Color, java.awt.geom.Point2D, java.awt.Color, boolean)

public GradientPaint(Point2D sample code for java.awt.geom.Point2D definition code for java.awt.geom.Point2D  pt1,
                     Color sample code for java.awt.Color definition code for java.awt.Color  color1,
                     Point2D sample code for java.awt.geom.Point2D definition code for java.awt.geom.Point2D  pt2,
                     Color sample code for java.awt.Color definition code for java.awt.Color  color2,
                     boolean cyclic)
Constructs either a cyclic or acyclic GradientPaint object depending on the boolean parameter.

Parameters:
pt1 - the first specified Point in user space
color1 - Color at the first specified Point
pt2 - the second specified Point in user space
color2 - Color at the second specified Point
cyclic - true if the gradient pattern should cycle repeatedly between the two colors; false otherwise
Throws:
NullPointerException sample code for java.lang.NullPointerException definition code for java.lang.NullPointerException - if either one of colors or points is null
Method Detail

getPoint1 sample code for java.awt.GradientPaint.getPoint1() definition code for java.awt.GradientPaint.getPoint1()

public Point2D sample code for java.awt.geom.Point2D definition code for java.awt.geom.Point2D  getPoint1()
Returns a copy of the point P1 that anchors the first color.

Returns:
a Point2D sample code for java.awt.geom.Point2D definition code for java.awt.geom.Point2D object that is a copy of the point that anchors the first color of this GradientPaint.

getColor1 sample code for java.awt.GradientPaint.getColor1() definition code for java.awt.GradientPaint.getColor1()

public Color sample code for java.awt.Color definition code for java.awt.Color  getColor1()
Returns the color C1 anchored by the point P1.

Returns:
a Color object that is the color anchored by P1.

getPoint2 sample code for java.awt.GradientPaint.getPoint2() definition code for java.awt.GradientPaint.getPoint2()

public Point2D sample code for java.awt.geom.Point2D definition code for java.awt.geom.Point2D  getPoint2()
Returns a copy of the point P2 which anchors the second color.

Returns:
a Point2D sample code for java.awt.geom.Point2D definition code for java.awt.geom.Point2D object that is a copy of the point that anchors the second color of this GradientPaint.

getColor2 sample code for java.awt.GradientPaint.getColor2() definition code for java.awt.GradientPaint.getColor2()

public Color sample code for java.awt.Color definition code for java.awt.Color  getColor2()
Returns the color C2 anchored by the point P2.

Returns:
a Color object that is the color anchored by P2.

isCyclic sample code for java.awt.GradientPaint.isCyclic() definition code for java.awt.GradientPaint.isCyclic()

public boolean isCyclic()
Returns true if the gradient cycles repeatedly between the two colors C1 and C2.

Returns:
true if the gradient cycles repeatedly between the two colors; false otherwise.

createContext sample code for java.awt.GradientPaint.createContext(java.awt.image.ColorModel, java.awt.Rectangle, java.awt.geom.Rectangle2D, java.awt.geom.AffineTransform, java.awt.RenderingHints) definition code for java.awt.GradientPaint.createContext(java.awt.image.ColorModel, java.awt.Rectangle, java.awt.geom.Rectangle2D, java.awt.geom.AffineTransform, java.awt.RenderingHints)

public PaintContext sample code for java.awt.PaintContext definition code for java.awt.PaintContext  createContext(ColorModel sample code for java.awt.image.ColorModel definition code for java.awt.image.ColorModel  cm,
                                  Rectangle sample code for java.awt.Rectangle definition code for java.awt.Rectangle  deviceBounds,
                                  Rectangle2D sample code for java.awt.geom.Rectangle2D definition code for java.awt.geom.Rectangle2D  userBounds,
                                  AffineTransform sample code for java.awt.geom.AffineTransform definition code for java.awt.geom.AffineTransform  xform,
                                  RenderingHints sample code for java.awt.RenderingHints definition code for java.awt.RenderingHints  hints)
Creates and returns a context used to generate the color pattern.

Specified by:
createContext sample code for java.awt.Paint.createContext(java.awt.image.ColorModel, java.awt.Rectangle, java.awt.geom.Rectangle2D, java.awt.geom.AffineTransform, java.awt.RenderingHints) definition code for java.awt.Paint.createContext(java.awt.image.ColorModel, java.awt.Rectangle, java.awt.geom.Rectangle2D, java.awt.geom.AffineTransform, java.awt.RenderingHints) in interface Paint sample code for java.awt.Paint definition code for java.awt.Paint
Parameters:
cm - ColorModel sample code for java.awt.image.ColorModel definition code for java.awt.image.ColorModel that receives the Paint data. This is used only as a hint.
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 AffineTransform sample code for java.awt.geom.AffineTransform definition code for java.awt.geom.AffineTransform from user space into device space
hints - the hints that the context object uses to choose between rendering alternatives
Returns:
the PaintContext sample code for java.awt.PaintContext definition code for java.awt.PaintContext that generates color patterns.
See Also:
PaintContext sample code for java.awt.PaintContext definition code for java.awt.PaintContext

getTransparency sample code for java.awt.GradientPaint.getTransparency() definition code for java.awt.GradientPaint.getTransparency()

public int getTransparency()
Returns the transparency mode for this GradientPaint.

Specified by:
getTransparency sample code for java.awt.Transparency.getTransparency() definition code for java.awt.Transparency.getTransparency() in interface Transparency sample code for java.awt.Transparency definition code for java.awt.Transparency
Returns:
an integer value representing this GradientPaint object's transparency mode.
See Also:
Transparency sample code for java.awt.Transparency definition code for java.awt.Transparency