This section illustrates you to display the shadow of the specified string.
To display the shadow, we have used the class GradientPaint to draw a box. The g.setStroke(new BasicStroke(15)) draw the wide lines. The class BasicStroke provides an stylistic way to draw an outline. The Font class defines the font.
The AffineTransform class provides translations, scaling, flipping, rotations, and shearing. The getScaleInstance(30.0, 30.0) returns a transform representing a scaling transformation. The class GlyphVector contains the geometric information in a transformed coordinate.
The method createGlyphVector() returns a new GlyphVector object, created with the specified String and the specified FontRenderContext. The method getFontRenderContext() gets the FontRenderContext by the FontMetrics object to measure text. The getGlyphOutline() method retrieves the outline . To outline the letters with a 5-pixel wide line, we have used the method setStroke(new BasicStroke(5.0f)).
To display the shadows for the letters specified, we have used the objects of Paint class and AffineTransform class. The method getShearInstance( -1.0, 0.0) returns a shearing transformation. By using g.translate(65, 270), we move to the first letter H
Following code displays the shadow of the letters.
| g.fill(affineTransform.createTransformedShape()) |
The method setPaint(paint) sets the shadow. The method g.draw() draws the outline of the letter specified.
Here is the code of DisplayShadow.java
import java.awt.*;
|
Output will be displayed as:

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.
Ask Questions? Discuss: Display the Shadow of the string
Post your Comment