下面的代码使用了Font,TextLayout和FontRenderContext对象来画出一个简单的24 point Times Bold(24点距,Times字体,粗体)的文本串。此处为完整的TimesB.java
源代码。
FontRenderContext frc = g2.getFontRenderContext();
Font f = new Font("Helvetica",Font.BOLD, 24);
String s = new String("24 Pont Helvetica Bold");
TextLayout tl = new TextLayout(s, f, frc);
Dimension theSize=getSize();
g2.setColor(Color.green);
tl.draw(g2, theSize.width/30, theSize.height/2);