package com.mindprod.example;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.SwingUtilities;
import java.awt.Color;
import java.awt.Font;
import java.awt.FontFormatException;
import java.io.IOException;
import java.io.InputStream;
import static java.lang.System.*;
/**
* demonstrate use of java.awt.Font.createFont.
* <p/>
* How to include a custom font with your application.
* <p/>
* Accessing an uninstalled Font bundled in a jar or on the classpath.
* <p/>
* Note this technique is illegal if you don't have licensing permission from the font designer. This only works in
* Swing!
*
* @author Roedy Green, Canadian Mind Products
* @version 1.0 2009-01-01 initial version
* @since 2009-01-01
*/
public final class TestCreateFont
{
/**
* Debugging harness for a Frame
*
* @param args command line arguments are ignored.
*/
public static void main( String args[] )
{
SwingUtilities.invokeLater( new Runnable()
{
public void run()
{
final JFrame frame = new JFrame();
try
{
InputStream fontStream = TestCreateFont.class
.getResourceAsStream( "IGLOOLAS.TTF" );
Font onePoint =
Font.createFont( Font.TRUETYPE_FONT, fontStream );
fontStream.close();
Font snowFont = onePoint.deriveFont( Font.PLAIN, 18 );
out.println( snowFont );
JLabel label = new JLabel( "SNOW ALERT" );
label.setBackground( Color.WHITE );
label.setForeground( Color.BLACK );
label.setFont( snowFont );
frame.getContentPane().add( label );
frame.setSize( 300, 100 );
frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
frame.validate();
frame.setVisible( true );
}
catch ( FontFormatException e )
{
err.println( "FontFormaException: " + e.getMessage() );
System.exit( 1 );
}
catch ( IOException e )
{
err.println( "IOException: " + e.getMessage() );
System.exit( 1 );
}
}
} );
}
}