Tue Nov 11, 2008 8:31 pm
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 = (Graphics2D) g;
Font font = new Font("Arial Narrow", Font.ITALIC, 20);
FontRenderContext fontRenderContext = g2d.getFontRenderContext();
g2d.translate(30, 60);
GlyphVector glyphVector = font.createGlyphVector(fontRenderContext,
"Java is a platform independent language.");
int len = glyphVector.getNumGlyphs();
for (int p = 0; p < len; p++) {
Point2D point = glyphVector.getGlyphPosition(p);
double angle = (double) p / (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(550, 380);
frame.show();
}
}
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com
Powered by phpBB © phpBB Group.