Search Here

Java program to display type and size of font


/* Identify the type and size of font */

import java.applet.Applet;
import java.awt.Font;
import java.awt.Graphics;
/*
 <applet code="MyFont" width=400 height=300>
 </applet>
*/
 
public class MyFont extends Applet
{
 public void paint(Graphics g)
 { 
  Font currentFont = g.getFont();
  String fontName = currentFont.getName();
  int size = currentFont.getSize(); 
  
  String fontStyle = "";
  
  if(currentFont.isBold())
   fontStyle = "Bold";
  
  if( currentFont.isItalic())
   fontStyle = "Italic";
  
  if( currentFont.isPlain())
   fontStyle = "Plain";
  
  String family = currentFont.getFamily();
  
  g.drawString("Font Name   : " + fontName, 100, 130);
  g.drawString("Font size   : " + size, 100, 150);
  g.drawString("Font Family : " + family, 100, 170);
  g.drawString("Font Style  : " + fontStyle, 100, 190);
 }
}

JAVA program to identify the type and size of your font
Output

No comments:

Post a Comment