- java.lang.Object
-
- java.awt.GradientPaint
-
- All Implemented Interfaces:
- Paint, Transparency
public class GradientPaint extends Object implements Paint
TheGradientPaint
class provides a way to fill aShape
with a linear color gradient pattern. IfPoint
P1 withColor
C1 andPoint
P2 withColor
C2 are specified in user space, theColor
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.- 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
Color
C1 while points on the P2 side have the constantColor
C2.
- See Also:
Paint
,Graphics2D.setPaint(java.awt.Paint)
-
-
Field Summary
-
Fields inherited from interface java.awt.Transparency
BITMASK, OPAQUE, TRANSLUCENT
-
-
Constructor Summary
Constructors Constructor and Description GradientPaint(float x1, float y1, Color color1, float x2, float y2, Color color2)
Constructs a simple acyclicGradientPaint
object.GradientPaint(float x1, float y1, Color color1, float x2, float y2, Color color2, boolean cyclic)
Constructs either a cyclic or acyclicGradientPaint
object depending on theboolean
parameter.GradientPaint(Point2D pt1, Color color1, Point2D pt2, Color color2)
Constructs a simple acyclicGradientPaint
object.GradientPaint(Point2D pt1, Color color1, Point2D pt2, Color color2, boolean cyclic)
Constructs either a cyclic or acyclicGradientPaint
object depending on theboolean
parameter.
-
Method Summary
Methods Modifier and Type Method and Description PaintContext
createContext(ColorModel cm, Rectangle deviceBounds, Rectangle2D userBounds, AffineTransform xform, RenderingHints hints)
Creates and returns aPaintContext
used to generate a linear color gradient pattern.Color
getColor1()
Returns the color C1 anchored by the point P1.Color
getColor2()
Returns the color C2 anchored by the point P2.Point2D
getPoint1()
Returns a copy of the point P1 that anchors the first color.Point2D
getPoint2()
Returns a copy of the point P2 which anchors the second color.int
getTransparency()
Returns the transparency mode for thisGradientPaint
.boolean
isCyclic()
Returnstrue
if the gradient cycles repeatedly between the two colors C1 and C2.
-
-
-
Constructor Detail
-
GradientPaint
public GradientPaint(float x1, float y1, Color color1, float x2, float y2, Color color2)
Constructs a simple acyclicGradientPaint
object.- Parameters:
x1
- x coordinate of the first specifiedPoint
in user spacey1
- y coordinate of the first specifiedPoint
in user spacecolor1
-Color
at the first specifiedPoint
x2
- x coordinate of the second specifiedPoint
in user spacey2
- y coordinate of the second specifiedPoint
in user spacecolor2
-Color
at the second specifiedPoint
- Throws:
NullPointerException
- if either one of colors is null
-
GradientPaint
public GradientPaint(Point2D pt1, Color color1, Point2D pt2, Color color2)
Constructs a simple acyclicGradientPaint
object.- Parameters:
pt1
- the first specifiedPoint
in user spacecolor1
-Color
at the first specifiedPoint
pt2
- the second specifiedPoint
in user spacecolor2
-Color
at the second specifiedPoint
- Throws:
NullPointerException
- if either one of colors or points is null
-
GradientPaint
public GradientPaint(float x1, float y1, Color color1, float x2, float y2, Color color2, boolean cyclic)
Constructs either a cyclic or acyclicGradientPaint
object depending on theboolean
parameter.- Parameters:
x1
- x coordinate of the first specifiedPoint
in user spacey1
- y coordinate of the first specifiedPoint
in user spacecolor1
-Color
at the first specifiedPoint
x2
- x coordinate of the second specifiedPoint
in user spacey2
- y coordinate of the second specifiedPoint
in user spacecolor2
-Color
at the second specifiedPoint
cyclic
-true
if the gradient pattern should cycle repeatedly between the two colors;false
otherwise
-
GradientPaint
@ConstructorProperties(value={"point1","color1","point2","color2","cyclic"}) public GradientPaint(Point2D pt1, Color color1, Point2D pt2, Color color2, boolean cyclic)
Constructs either a cyclic or acyclicGradientPaint
object depending on theboolean
parameter.- Parameters:
pt1
- the first specifiedPoint
in user spacecolor1
-Color
at the first specifiedPoint
pt2
- the second specifiedPoint
in user spacecolor2
-Color
at the second specifiedPoint
cyclic
-true
if the gradient pattern should cycle repeatedly between the two colors;false
otherwise- Throws:
NullPointerException
- if either one of colors or points is null
-
-
Method Detail
-
getPoint1
public Point2D getPoint1()
Returns a copy of the point P1 that anchors the first color.- Returns:
- a
Point2D
object that is a copy of the point that anchors the first color of thisGradientPaint
.
-
getColor1
public Color getColor1()
Returns the color C1 anchored by the point P1.- Returns:
- a
Color
object that is the color anchored by P1.
-
getPoint2
public Point2D getPoint2()
Returns a copy of the point P2 which anchors the second color.- Returns:
- a
Point2D
object that is a copy of the point that anchors the second color of thisGradientPaint
.
-
getColor2
public Color getColor2()
Returns the color C2 anchored by the point P2.- Returns:
- a
Color
object that is the color anchored by P2.
-
isCyclic
public boolean isCyclic()
Returnstrue
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
public PaintContext createContext(ColorModel cm, Rectangle deviceBounds, Rectangle2D userBounds, AffineTransform xform, RenderingHints hints)
Creates and returns aPaintContext
used to generate a linear color gradient pattern. See thespecification
of the method in thePaint
interface for information on null parameter handling.- Specified by:
createContext
in interfacePaint
- Parameters:
cm
- the preferredColorModel
which represents the most convenient format for the caller to receive the pixel data, ornull
if 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
- theAffineTransform
from user space into device space.hints
- the set of hints that the context object can use to choose between rendering alternatives.- Returns:
- the
PaintContext
for generating color patterns. - See Also:
Paint
,PaintContext
,ColorModel
,Rectangle
,Rectangle2D
,AffineTransform
,RenderingHints
-
getTransparency
public int getTransparency()
Returns the transparency mode for thisGradientPaint
.- Specified by:
getTransparency
in interfaceTransparency
- Returns:
- an integer value representing this
GradientPaint
object's transparency mode. - See Also:
Transparency
-
-
Nederlandse vertaling
U hebt gevraagd om deze site in het Nederlands te bezoeken. Voor nu wordt alleen de interface vertaald, maar nog niet alle inhoud.Als je me wilt helpen met vertalingen, is je bijdrage welkom. Het enige dat u hoeft te doen, is u op de site registreren en mij een bericht sturen waarin u wordt gevraagd om u toe te voegen aan de groep vertalers, zodat u de gewenste pagina's kunt vertalen. Een link onderaan elke vertaalde pagina geeft aan dat u de vertaler bent en heeft een link naar uw profiel.
Bij voorbaat dank.
Document heeft de 11/06/2005 gemaakt, de laatste keer de 04/03/2020 gewijzigd
Bron van het afgedrukte document:https://www.gaudry.be/nl/java-api-rf-java/awt/GradientPaint.html
De infobrol is een persoonlijke site waarvan de inhoud uitsluitend mijn verantwoordelijkheid is. De tekst is beschikbaar onder CreativeCommons-licentie (BY-NC-SA). Meer info op de gebruiksvoorwaarden en de auteur.
Referenties
Deze verwijzingen en links verwijzen naar documenten die geraadpleegd zijn tijdens het schrijven van deze pagina, of die aanvullende informatie kunnen geven, maar de auteurs van deze bronnen kunnen niet verantwoordelijk worden gehouden voor de inhoud van deze pagina.
De auteur Deze site is als enige verantwoordelijk voor de manier waarop de verschillende concepten, en de vrijheden die met de referentiewerken worden genomen, hier worden gepresenteerd. Vergeet niet dat u meerdere broninformatie moet doorgeven om het risico op fouten te verkleinen.