Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions? | Software Development
 

Show Text effect

Text effect gives the stylistic way to design headings. To rotate the text, we have used AffineTransform class that defines different properties like rotation, translation, scaling and shearing etc.

Show Text effect

                         

This section illustrates you how to rotate the text and makes it transparent.

Text effect gives the stylistic way to design headings. To rotate the text, we have used AffineTransform class that defines different properties like rotation, translation, scaling and shearing etc. The method getRotateInstance(Math.PI * (num1 - 1.0f))) of AffineTransform class returns a rotation transformation which will rotate the text. The  Math class performs all the numeric operations. The Font class defines the font.

The Dimension class defines the height and width of a component. These dimensions are used by the method getTranslateInstance( dim.width / 2,dim.height * 3 / 4) which returns the translation transformation.

To give the blending and transparency effects with graphics and images and combines source and destination colors, we used the class AlphaComposite. The method getInstance(AlphaComposite.SRC_OVER,num2)) of AlphaComposite class defines the rule SRC_OVER which composites the source over the destination.

Here is the code of TextRenderingExample.java

import java.awt.*;
import javax.swing.*;
import java.awt.geom.*;

public class TextRenderingExample extends JPanel {
  public void paint(Graphics g) {
    Graphics2D g2d = (Graphics2D) g;
    Dimension dim = getSize();
    AffineTransform affineTransform = AffineTransform.getTranslateInstance(
    dim.width / 2,dim.height * 4);
    g2d.transform(affineTransform);

    String st = "Welcome";
    Font font = new Font("Book Antiqua", Font.PLAIN, 50);
    g2d.setFont(font);
    g2d.setColor(Color.red);
    int counter = 18;
    for (int k = 1; k <= counter; k++) {
      AffineTransform transform = g2d.getTransform();
      float num1 = (float) k / (float) counter;
      g2d.transform(AffineTransform.getRotateInstance(Math.PI
          * (num1 - 1.0f)));
      float num2 = ((k == counter) ? 1.0f : num1 / 3);
      g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
          num2));
      g2d.drawString(st, 00);
    g2d.setTransform(transform);
    }
  }
 public static void main(String[] args) {
    JFrame frame = new JFrame("Text Rendering Example");
    frame.getContentPane().add(new TextRenderingExample());
    frame.setSize(450350);
    frame.show();
  }
}

Output will be displayed as:

Download Source Code

                         

» View all related tutorials
Related Tags: c ide class methods method get icon height vi width change using int id ai create js define show paint

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
 
Tell A Friend
Your Friend Name

 

 
Recently Viewed
Software Solutions
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.