【Java开源代码栏目提醒】:文章导读:在新的一年中,各位网友都进入紧张的学习或是工作阶段。网学会员整理了Java开源代码-TextLayoutTest.java的相关内容供大家参考,祝大家在新的一年里工作和学习顺利!
import java.awt.geom.*;
import java.awt.image.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.font.*;
import javax.swing.*;
import javax.swing.event.*;
public class TextLayoutTest extends JFrame
{
public static void main(String arg[])
{
JFrame frame =new TextLayoutTest();
frame.setBackground(Color.white);
frame.setVisible(true);
}
public TextLayoutTest()
{
setSize(250, 250);
}
protected void processWindowEvent(WindowEvent e)
{
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING)
{
System.exit(0);
}
}
public void paint(Graphics g)
{
Graphics2D g2d = (Graphics2D)g;
TextLayout text =
new TextLayout("Text",
new Font("Helvetica", 1, 96),
new FontRenderContext(null, false, false));
AffineTransform textAt = new AffineTransform();
textAt.translate(20, (float)text.getBounds().getHeight()+40);
Shape shape = text.getOutline(textAt);
// GradientPaint gp = new GradientPaint(40, 40, Color.white, 150, 150, Color.red, false);
// g2d.setPaint(gp);
BufferedImage bi = new BufferedImage(5, 5, BufferedImage.TYPE_INT_RGB);
Graphics2D big = bi.createGraphics();
big.setColor(Color.blue);
big.fillRect(0, 0, 5, 5);
big.setColor(Color.lightGray);
big.fillOval(0, 0, 5, 5);
Rectangle r = new Rectangle(0,0,5,5);
g2d.setPaint(new TexturePaint(bi, r));
g2d.draw(shape);
g2d.fill(shape);
}
}
上一篇:
TextJDOMparseXML.java
下一篇:
英语论文网([网学网]):英语专业本科生毕业论文写作