Switch to full style
General Java code examples
Post a reply

draw text effects in java

Tue Nov 11, 2008 6:54 pm

draw text effects in java
Code:
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 * 3 / 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, 0, 0);
    g2d.setTransform(transform);
    }
  }
public static void main(String[] args) {
    JFrame frame = new JFrame("Text Rendering Example");
    frame.getContentPane().add(new TextRenderingExample());
    frame.setSize(450, 350);
    frame.show();
  }
}



Attachments
textRendering.gif
output

Post a reply
  Related Posts  to : draw text effects in java
 java image effects     -  
 Java- Copy text area into disabled text area     -  
 Draw An Arc in java     -  
 Draw Flag in Java     -  
 draw Calendar in java     -  
 draw Oval in java     -  
 Draw Dashed Oval in java     -  
 Changing the color of a graph draw in java     -  
 Java code to draw shortest path tree     -  
 Using Filters Effects     -