java多种改变字体样式实例

时间:2012-12-01 14:45:59
【文件属性】:

文件名称:java多种改变字体样式实例

文件大小:9KB

文件格式:RAR

更新时间:2012-12-01 14:45:59

java

import java.awt.*; import java.awt.event.*; import java.awt.geom.*; import java.awt.font.*; public class Clipping extends Canvas { public Clipping() { setBackground(Color.white); } public void paint(Graphics g) { Graphics2D g2; g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); int w = getSize().width; int h = getSize().height; FontRenderContext frc = g2.getFontRenderContext(); Font f = new Font("Helvetica",Font.BOLD,w/8); String s = new String("By"); TextLayout tl = new TextLayout(s, f, frc); float sw = (float) tl.getBounds().getWidth(); AffineTransform transform = new AffineTransform(); transform.setToTranslation(w/2-sw/2,h/2); Shape shape = tl.getOutline(transform); g2.setClip(shape); g2.setColor(Color.blue); g2.fill(shape.getBounds()); g2.setColor(Color.yellow); for (int j = shape.getBounds().y; j < shape.getBounds().y + shape.getBounds().height; j=j+3) { Line2D line = new Line2D.Float( 0.0f, (float) j, (float) w, (float) j); g2.draw(line); } } public static void main(String s[]) { WindowListener l = new WindowAdapter() { public void windowClosing(WindowEvent e) {System.exit(0);} public void windowClosed(WindowEvent e) {System.exit(0);} }; Frame f = new Frame("2D Text"); f.addWindowListener(l); f.add("Center", new Clipping()); f.pack(); f.setSize(new Dimension(400, 300)); f.show(); } } *********************************************


【文件预览】:
字体样式
----test1.java(2KB)
----MakeImage.java(2KB)
----SampleUtils.java(5KB)
----StillLife.java(2KB)
----TimesB.java(1KB)
----LineBreakSample.java(3KB)
----Starry.java(2KB)
----DocColorTest.java(1KB)
----TextClipping.java(2KB)
----Clipping.java(2KB)

网友评论

  • 这个分数下载这个东西真的有点亏,不值得!