The interface Stroke gives the stylish way of representing the outlines. To show the effect, class GradientPaint is used which fills the specified figure in a color gradient pattern. The class Rectangle2D provides the rectangle figure.
Show Stroke with Effect
This section illustrates you how to show stroke with effect.
The interface Stroke gives the stylish way of representing the outlines. To show the effect, class GradientPaint is used which fills the specified figure in a color gradient pattern. The class Rectangle2D provides the rectangle figure.
Following code shows the simple rectangle filled with color gradient pattern:
g2d.setPaint(gradientPaint); g2d.fill(rectangle); |
Following code shows the stroke inside the rectangle:
rectangle.setFrame(p + 90, q, width, height); g2d.setPaint(gradientPaint); g2d.setStroke(new BasicStroke(10)); g2d.draw(rectangle); |
Following code strokes with gradient:
rectangle.setFrame(p + 180, q, width, height); g2d.setPaint(Color.black); g2d.draw(rectangle); |
The method setFrame() sets the size of the rectangle. The setPaint(gradientPaint) paints the rectangle in a gradient pattern. The method setStroke() sets the stroke settings for the Graphics2D context, when you draw the shape. The integer value passed into the constructor of class BasicStroke represents the thickness of the outline.
Here is the code of EffectsOfStroke.java
import java.awt.*;
|
Output will be displayed as: