FileDocCategorySizeDatePackage
FontShow.javaAPI DocExample1410Tue Mar 25 13:05:08 GMT 1997None

FontShow

public class FontShow extends Applet

Fields Summary
static final int
LPAD
boolean
bigFont
Constructors Summary
Methods Summary
public voidinit()


	   
		addMouseListener( new MouseAdapter() {
			public void mouseClicked(MouseEvent e) {
				bigFont = !bigFont;
				repaint();
			}
		} );
	
public voidpaint(java.awt.Graphics g)

		String message = getParameter( "word" );
		g.drawRect(0, 0, getSize().width-1, getSize().height-1);

		if ( bigFont )
			g.setFont( new Font("Dialog",Font.PLAIN,24) );
		else
			g.setFont( new Font("Dialog",Font.PLAIN,12) );

		FontMetrics metrics = g.getFontMetrics();
		int fontAscent = metrics.getMaxAscent ();
		int fontDescent = metrics.getMaxDescent();
		int messWidth = metrics.stringWidth ( message );
		// Center text
		int startX = getSize().width/2 - messWidth/2;
		int startY = getSize().height/2 - fontDescent/2 + fontAscent/2;

		g.drawString(message, startX, startY);

		g.setColor( Color.white );	// Base lines
		g.drawLine( startX-LPAD, startY, startX+messWidth+LPAD, startY );
		g.drawLine( startX, startY+ LPAD, startX, startY-fontAscent-LPAD );
		g.setColor( Color.green );	// Ascent line
		g.drawLine( startX-LPAD, startY-fontAscent, startX+messWidth+LPAD, startY-fontAscent );
		g.setColor( Color.red );	// Descent line
		g.drawLine( startX-LPAD, startY+fontDescent, startX+messWidth+LPAD, startY+fontDescent );