Simple Font Paint Example

A font is a specific style of displaying characters. It describes the design, size, appearance, weight, and spacing of a character. It is the combination of pitch and spacing.

Simple Font Paint Example

     

This section illustrates you how to paint the font.

A font is a specific style of displaying characters. It describes the design, size, appearance, weight, and spacing of a character. It is the combination of pitch and spacing.

Following code defines the font specified:

Font font = new Font("Monotype Corsiva", Font.BOLD, 20)

1. Class FontRenderContext measures the text specified. 
2. A glyph is an element of writing and displaying characters in a style. Class GlyphVector provides a collection of glyphs containing geometric information. 

Here is the code of SimpleFontPaintExample.java

import java.awt.*;
import javax.swing.*;
import java.awt.font.GlyphVector;
import java.awt.font.FontRenderContext;

public class SimpleFontPaintExample extends JPanel{
        public void paint(Graphics g) {
        Graphics2D g2d = (Graphics2D)g;

        String st = "Java is an Object Oriented Programming Language.";
        Font font = new Font("Monotype Corsiva", Font.BOLD, 20);
        FontRenderContext fontRendContext = g2d.getFontRenderContext();
        GlyphVector glyphVector = font.createGlyphVector(fontRendContext, st);
        g2d.drawGlyphVector(glyphVector, 30, 50);
      }
    public static void main(String[] args) {
    JFrame frame = new JFrame("Font Paint Example");
    frame.getContentPane().add(new SimpleFontPaintExample());
    frame.setSize(500, 150);
    frame.show();
  }
} 

Output will be displayed as:

Download source Code

Advertisements

Ads

 

We have 1000s of tutorials on our website. Search Tutorials tutorials on our website.

Share on Google+Share on Google+

Simple Font Paint Example

Posted on: October 8, 2008 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Advertisements

Ads
 

Discuss: Simple Font Paint Example  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0

Ads

 

Ads