 |
|
|
FontViewer.java
|
/*
* Author: Havard Rast Blok
* E-mail:
* Web : www.rememberjava.com
*/
import java.awt.*;
import javax.swing.*;
/**
* An application to view a specified font.
*/
public class FontViewer extends JFrame
{
private Font f;
public FontViewer(String name, int style, int size)
{
super("FontViewer");
//make font
f = new Font( name, style, size);
//show frame
setSize( 300, 200 );
show();
}
public void paint(Graphics g)
{
//show font
g.setFont(f);
g.drawString("Hello World!", 20, 150);
}
public static void main(String[] args)
{
int style=0;
// check and parse the command line arguments
if( args.length < 2 )
{
System.out.println("Usage: java FontViewer <fontname> <size> [bold] [italic]");
System.exit(1);
}
for(int i=2; i<args.length; i++)
{
if( args[i].compareToIgnoreCase("bold") == 0 )
{
style += Font.BOLD;
}
else if( args[i].compareToIgnoreCase("italic") == 0 )
{
style += Font.ITALIC;
}
}
new FontViewer( args[0], style, Integer.parseInt(args[1]));
}
}
|
|
|
 |