FileDocCategorySizeDatePackage
TextRendering.javaAPI DocExample1495Mon Apr 05 10:25:44 BST 1999None

TextRendering

public class TextRendering extends Object

Fields Summary
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] args)

    Frame frame = new ApplicationFrame("TextRendering v1.0") {
      public void paint(Graphics g) {
        Graphics2D g2 = (Graphics2D)g;
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
            RenderingHints.VALUE_ANTIALIAS_ON);

        // Transform the origin to the bottom center of the window.
        Dimension d = getSize();
        AffineTransform ct = AffineTransform.getTranslateInstance(
            d.width / 2, d.height * 3 / 4);
        g2.transform(ct);
        
        // Get an appropriate font.
        String s = "jade";
        Font f = new Font("Serif", Font.PLAIN, 128);
        g2.setFont(f);
        
        int limit = 6;
        for (int i = 1; i <= limit; i++) {
          // Save the original transformation.
          AffineTransform oldTransform = g2.getTransform();
              
          float ratio = (float)i / (float)limit;
          g2.transform(AffineTransform.getRotateInstance(
              Math.PI * (ratio - 1.0f)));
          float alpha = ((i == limit) ? 1.0f : ratio / 3);
          g2.setComposite(AlphaComposite.getInstance(
              AlphaComposite.SRC_OVER, alpha));
          g2.drawString(s, 0, 0);
          
          // Restore the original transformation.
          g2.setTransform(oldTransform);
        }
      }
    };
    frame.setVisible(true);