Tue Nov 11, 2008 6:54 pm
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();
}
}
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.