by Dinesh Thakur Category: Java 2D Example

This code can be seen as built a clipping path with the content of the text area of the word "Java " located in the middle of the window.In the drawn area can be seen as the image is painted behind the chain. As seen, the effect is very colorful and easy to perform.

import java.applet.Applet;

import java.awt.*;
import java.awt.event.*;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.RenderingHints;
import java.awt.font.FontRenderContext;
import java.awt.font.TextLayout;
import java.awt.geom.*;
import java.awt.image.*;
import java.awt.Shape;
import javax.swing.*;
public class DrawTextEffectExample extends Applet {
public static void main(String[] args) {
Frame DrawTextEffect  = new Frame("Draw TextEffect  Example");
DrawTextEffect .setSize(350, 250);
Applet DrawTextEffectExample = new DrawTextEffectExample();
DrawTextEffect .add(DrawTextEffectExample);
DrawTextEffect .setVisible(true);
DrawTextEffect .addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
  public void paint(Graphics g) {
    g.setFont(new Font("Arial",Font.BOLD,14));
    g.drawString("Text Effect in Java Example", 50, 40);
    g.setFont(new Font("Arial",Font.BOLD,10));
    g.drawString("", 200, 205);
                Graphics2D G2D = (Graphics2D)g;
                int w = getSize().width;
                int h = getSize().height;
                Image image = (new ImageIcon("Canada.jpg")).getImage();
                FontRenderContext FontRC = G2D.getFontRenderContext();
                Font font = new Font("Times",Font.BOLD,100);
                TextLayout TextLay = new TextLayout("Java",font,FontRC);
                float sw = (float)TextLay.getBounds().getWidth();
                AffineTransform AffineTran = new AffineTransform();
                Shape s = TextLay.getOutline(AffineTran);

Text Effect in Java Example

About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.C.A, MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.