explain choosing font faces and sizes in java awt


Explain Choosing Font Faces and Sizes in java AWT packages?

Choosing a font face is simple. First you create a new Font object. Then you call g.setFont(Font f). To instantiate a Font object uses this constructor:

public Font(String name, int style, int size)

name is the name of the font family, e.g. "Serif", "SansSerif", or "Mono".

size is the size of the font in points. In computer graphics a point is considered to be equal to one pixel. 12 points is a general size font. 14 points is possible better on most computer displays. Smaller point sizes look good on paper printed along with a high resolution printer, but not in the lower resolutions of a computer monitor.

style is an mnemonic constant from java.awt.Font that tells while the text will be bold, italic or plain. The three constants are Font.PLAIN, Font.BOLD, and Font.ITALIC. The program below prints each font in its own face and 14 point bold.

import java.applet.*;
import java.awt.*;

public class FancyFontList extends Applet {

private String[] availableFonts;

public void init () {

Toolkit t = Toolkit.getDefaultToolkit();
availableFonts = t.getFontList();

}

public void paint(Graphics g) {

for (int i = 0; i < availableFonts.length; i++) {
Font f = new Font(availableFonts[i], Font.BOLD, 14);
g.setFont(f);
g.drawString(availableFonts[i], 5, 15*i + 15);
}
}

}

Request for Solution File

Ask an Expert for Answer!!
JAVA Programming: explain choosing font faces and sizes in java awt
Reference No:- TGS0285275

Expected delivery within 24 Hours