- java.lang.Object
- 
- java.awt.BasicStroke
 
- 
- All Implemented Interfaces:
- Stroke
 
 public class BasicStroke extends Object implements Stroke TheBasicStrokeclass defines a basic set of rendering attributes for the outlines of graphics primitives, which are rendered with aGraphics2Dobject that has its Stroke attribute set to thisBasicStroke. The rendering attributes defined byBasicStrokedescribe the shape of the mark made by a pen drawn along the outline of aShapeand the decorations applied at the ends and joins of path segments of theShape. These rendering attributes include:- width
- The pen width, measured perpendicularly to the pen trajectory.
- end caps
- The decoration applied to the ends of unclosed subpaths and
 dash segments.  Subpaths that start and end on the same point are
 still considered unclosed if they do not have a CLOSE segment.
 See SEG_CLOSEfor more information on the CLOSE segment. The three different decorations are:CAP_BUTT,CAP_ROUND, andCAP_SQUARE.
- line joins
- The decoration applied at the intersection of two path segments
 and at the intersection of the endpoints of a subpath that is closed
 using SEG_CLOSE. The three different decorations are:JOIN_BEVEL,JOIN_MITER, andJOIN_ROUND.
- miter limit
- The limit to trim a line join that has a JOIN_MITER decoration. A line join is trimmed when the ratio of miter length to stroke width is greater than the miterlimit value. The miter length is the diagonal length of the miter, which is the distance between the inside corner and the outside corner of the intersection. The smaller the angle formed by two line segments, the longer the miter length and the sharper the angle of intersection. The default miterlimit value of 10.0f causes all angles less than 11 degrees to be trimmed. Trimming miters converts the decoration of the line join to bevel.
- dash attributes
- The definition of how to make a dash pattern by alternating between opaque and transparent sections.
 Shapeargument. When aGraphics2Dobject uses aStrokeobject to redefine a path during the execution of one of itsdrawmethods, the geometry is supplied in its original form before theGraphics2Dtransform attribute is applied. Therefore, attributes such as the pen width are interpreted in the user space coordinate system of theGraphics2Dobject and are subject to the scaling and shearing effects of the user-space-to-device-space transform in that particularGraphics2D. For example, the width of a rendered shape's outline is determined not only by the width attribute of thisBasicStroke, but also by the transform attribute of theGraphics2Dobject. Consider this code:
 Assuming there are no other scaling transforms added to the// sets the Graphics2D object's Transform attribute g2d.scale(10, 10); // sets the Graphics2D object's Stroke attribute g2d.setStroke(new BasicStroke(1.5f));Graphics2Dobject, the resulting line will be approximately 15 pixels wide. As the example code demonstrates, a floating-point line offers better precision, especially when large transforms are used with aGraphics2Dobject. When a line is diagonal, the exact width depends on how the rendering pipeline chooses which pixels to fill as it traces the theoretical widened outline. The choice of which pixels to turn on is affected by the antialiasing attribute because the antialiasing rendering pipeline can choose to color partially-covered pixels.For more information on the user space coordinate system and the rendering process, see the Graphics2Dclass comments.- See Also:
- Graphics2D
 
- 
- 
Field SummaryFields Modifier and Type Field Description static intCAP_BUTTEnds unclosed subpaths and dash segments with no added decoration.static intCAP_ROUNDEnds unclosed subpaths and dash segments with a round decoration that has a radius equal to half of the width of the pen.static intCAP_SQUAREEnds unclosed subpaths and dash segments with a square projection that extends beyond the end of the segment to a distance equal to half of the line width.static intJOIN_BEVELJoins path segments by connecting the outer corners of their wide outlines with a straight segment.static intJOIN_MITERJoins path segments by extending their outside edges until they meet.static intJOIN_ROUNDJoins path segments by rounding off the corner at a radius of half the line width.
 - 
Constructor SummaryConstructors Constructor Description BasicStroke()Constructs a newBasicStrokewith defaults for all attributes.BasicStroke(float width)Constructs a solidBasicStrokewith the specified line width and with default values for the cap and join styles.BasicStroke(float width, int cap, int join)Constructs a solidBasicStrokewith the specified attributes.BasicStroke(float width, int cap, int join, float miterlimit)Constructs a solidBasicStrokewith the specified attributes.BasicStroke(float width, int cap, int join, float miterlimit, float[] dash, float dash_phase)Constructs a newBasicStrokewith the specified attributes.
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description ShapecreateStrokedShape(Shape s)Returns aShapewhose interior defines the stroked outline of a specifiedShape.booleanequals(Object obj)Tests if a specified object is equal to thisBasicStrokeby first testing if it is aBasicStrokeand then comparing its width, join, cap, miter limit, dash, and dash phase attributes with those of thisBasicStroke.float[]getDashArray()Returns the array representing the lengths of the dash segments.floatgetDashPhase()Returns the current dash phase.intgetEndCap()Returns the end cap style.intgetLineJoin()Returns the line join style.floatgetLineWidth()Returns the line width.floatgetMiterLimit()Returns the limit of miter joins.inthashCode()Returns the hashcode for this stroke.
 
- 
- 
- 
Field Detail- 
JOIN_MITER@Native public static final int JOIN_MITER Joins path segments by extending their outside edges until they meet.- See Also:
- Constant Field Values
 
 - 
JOIN_ROUND@Native public static final int JOIN_ROUND Joins path segments by rounding off the corner at a radius of half the line width.- See Also:
- Constant Field Values
 
 - 
JOIN_BEVEL@Native public static final int JOIN_BEVEL Joins path segments by connecting the outer corners of their wide outlines with a straight segment.- See Also:
- Constant Field Values
 
 - 
CAP_BUTT@Native public static final int CAP_BUTT Ends unclosed subpaths and dash segments with no added decoration.- See Also:
- Constant Field Values
 
 - 
CAP_ROUND@Native public static final int CAP_ROUND Ends unclosed subpaths and dash segments with a round decoration that has a radius equal to half of the width of the pen.- See Also:
- Constant Field Values
 
 - 
CAP_SQUARE@Native public static final int CAP_SQUARE Ends unclosed subpaths and dash segments with a square projection that extends beyond the end of the segment to a distance equal to half of the line width.- See Also:
- Constant Field Values
 
 
- 
 - 
Constructor Detail- 
BasicStroke@ConstructorProperties({"lineWidth","endCap","lineJoin","miterLimit","dashArray","dashPhase"}) public BasicStroke(float width, int cap, int join, float miterlimit, float[] dash, float dash_phase) Constructs a newBasicStrokewith the specified attributes.- Parameters:
- width- the width of this- BasicStroke. The width must be greater than or equal to 0.0f. If width is set to 0.0f, the stroke is rendered as the thinnest possible line for the target device and the antialias hint setting.
- cap- the decoration of the ends of a- BasicStroke
- join- the decoration applied where path segments meet
- miterlimit- the limit to trim the miter join. The miterlimit must be greater than or equal to 1.0f.
- dash- the array representing the dashing pattern
- dash_phase- the offset to start the dashing pattern
- Throws:
- IllegalArgumentException- if- widthis negative
- IllegalArgumentException- if- capis not either CAP_BUTT, CAP_ROUND or CAP_SQUARE
- IllegalArgumentException- if- miterlimitis less than 1 and- joinis JOIN_MITER
- IllegalArgumentException- if- joinis not either JOIN_ROUND, JOIN_BEVEL, or JOIN_MITER
- IllegalArgumentException- if- dash_phaseis negative and- dashis not- null
- IllegalArgumentException- if the length of- dashis zero
- IllegalArgumentException- if dash lengths are all zero.
 
 - 
BasicStrokepublic BasicStroke(float width, int cap, int join, float miterlimit)Constructs a solidBasicStrokewith the specified attributes.- Parameters:
- width- the width of the- BasicStroke
- cap- the decoration of the ends of a- BasicStroke
- join- the decoration applied where path segments meet
- miterlimit- the limit to trim the miter join
- Throws:
- IllegalArgumentException- if- widthis negative
- IllegalArgumentException- if- capis not either CAP_BUTT, CAP_ROUND or CAP_SQUARE
- IllegalArgumentException- if- miterlimitis less than 1 and- joinis JOIN_MITER
- IllegalArgumentException- if- joinis not either JOIN_ROUND, JOIN_BEVEL, or JOIN_MITER
 
 - 
BasicStrokepublic BasicStroke(float width, int cap, int join)Constructs a solidBasicStrokewith the specified attributes. Themiterlimitparameter is unnecessary in cases where the default is allowable or the line joins are not specified as JOIN_MITER.- Parameters:
- width- the width of the- BasicStroke
- cap- the decoration of the ends of a- BasicStroke
- join- the decoration applied where path segments meet
- Throws:
- IllegalArgumentException- if- widthis negative
- IllegalArgumentException- if- capis not either CAP_BUTT, CAP_ROUND or CAP_SQUARE
- IllegalArgumentException- if- joinis not either JOIN_ROUND, JOIN_BEVEL, or JOIN_MITER
 
 - 
BasicStrokepublic BasicStroke(float width) Constructs a solidBasicStrokewith the specified line width and with default values for the cap and join styles.- Parameters:
- width- the width of the- BasicStroke
- Throws:
- IllegalArgumentException- if- widthis negative
 
 - 
BasicStrokepublic BasicStroke() Constructs a newBasicStrokewith defaults for all attributes. The default attributes are a solid line of width 1.0, CAP_SQUARE, JOIN_MITER, a miter limit of 10.0.
 
- 
 - 
Method Detail- 
createStrokedShapepublic Shape createStrokedShape(Shape s) Returns aShapewhose interior defines the stroked outline of a specifiedShape.- Specified by:
- createStrokedShapein interface- Stroke
- Parameters:
- s- the- Shapeboundary be stroked
- Returns:
- the Shapeof the stroked outline.
 
 - 
getLineWidthpublic float getLineWidth() Returns the line width. Line width is represented in user space, which is the default-coordinate space used by Java 2D. See theGraphics2Dclass comments for more information on the user space coordinate system.- Returns:
- the line width of this BasicStroke.
- See Also:
- Graphics2D
 
 - 
getEndCappublic int getEndCap() Returns the end cap style.- Returns:
- the end cap style of this BasicStrokeas one of the staticintvalues that define possible end cap styles.
 
 - 
getLineJoinpublic int getLineJoin() Returns the line join style.- Returns:
- the line join style of the BasicStrokeas one of the staticintvalues that define possible line join styles.
 
 - 
getMiterLimitpublic float getMiterLimit() Returns the limit of miter joins.- Returns:
- the limit of miter joins of the BasicStroke.
 
 - 
getDashArraypublic float[] getDashArray() Returns the array representing the lengths of the dash segments. Alternate entries in the array represent the user space lengths of the opaque and transparent segments of the dashes. As the pen moves along the outline of theShapeto be stroked, the user space distance that the pen travels is accumulated. The distance value is used to index into the dash array. The pen is opaque when its current cumulative distance maps to an even element of the dash array and transparent otherwise.- Returns:
- the dash array.
 
 - 
getDashPhasepublic float getDashPhase() Returns the current dash phase. The dash phase is a distance specified in user coordinates that represents an offset into the dashing pattern. In other words, the dash phase defines the point in the dashing pattern that will correspond to the beginning of the stroke.- Returns:
- the dash phase as a floatvalue.
 
 - 
hashCodepublic int hashCode() Returns the hashcode for this stroke.- Overrides:
- hashCodein class- Object
- Returns:
- a hash code for this stroke.
- See Also:
- Object.equals(java.lang.Object),- System.identityHashCode(java.lang.Object)
 
 - 
equalspublic boolean equals(Object obj) Tests if a specified object is equal to thisBasicStrokeby first testing if it is aBasicStrokeand then comparing its width, join, cap, miter limit, dash, and dash phase attributes with those of thisBasicStroke.- Overrides:
- equalsin class- Object
- Parameters:
- obj- the specified object to compare to this- BasicStroke
- Returns:
- trueif the width, join, cap, miter limit, dash, and dash phase are the same for both objects;- falseotherwise.
- See Also:
- Object.hashCode(),- HashMap
 
 
- 
 
-