Switch to full style
General Java code examples
Post a reply

text like a curve

Tue Nov 11, 2008 8:31 pm

draw text like a curve in java
Code:
import java.awt.*;
import javax.swing.*;
import java.awt.font.*;
import java.awt.geom.*;

public class 
ShowTextCreateCurve extends JPanel {
  public 
void paint(Graphics g) {
    
Graphics2D g2d = (Graphics2Dg;

    
Font font = new Font("Arial Narrow"Font.ITALIC20);
    
FontRenderContext fontRenderContext g2d.getFontRenderContext();
    
g2d.translate(3060);

    
GlyphVector glyphVector font.createGlyphVector(fontRenderContext,
        
"Java is a platform independent language.");
    
int len glyphVector.getNumGlyphs();
    for (
int p 0lenp++) {
      
Point2D point glyphVector.getGlyphPosition(p);
      
double angle = (double) / (double) (len 1) * Math.PI 2.5;
      
AffineTransform affineTransform AffineTransform.getTranslateInstance(
          
point.getX(),point.getY());
      
affineTransform.rotate(angle);
      
Shape shape1 glyphVector.getGlyphOutline(p);
      
Shape shape2 affineTransform.createTransformedShape(shape1);
      
g2d.setPaint(Color.red);
      
g2d.fill(shape2);
    }
  }
  public static 
void main(String[] args) {
    
JFrame frame = new JFrame("Show Rolling Text");
    
frame.getContentPane().add(new ShowTextCreateCurve());
    
frame.setSize(550380);
    
frame.show();
  }



Attachments
rollingText.gif
text curve
rollingText.gif (7.95 KiB) Viewed 5680 times

Post a reply
  Related Posts  to : text like a curve
 Curve XY 2D     -  
 Draw Hermite Curve     -  
 Curve Control Point in java     -  
 Able to Copy Text from Uneditable Text Boxes(JTextfields)     -  
 Draw Bezier Curve and selecting the points with mouse click     -  
 Draw curves using Hermite Curve equations with mouse clicks     -  
 Java- Copy text area into disabled text area     -  
 draw 2d curve with showing x axis and y axis     -  
 i tag for italic text     -  
 Get Text Field value by php     -  

Topic Tags

Java Graphics