Solution
Download FontTest source code.
HTML Interface to Applet
<APPLET CODEBASE="/applets/magelang/AWT-Training/classes/" CODE="FontTest.class" WIDTH=400 HEIGHT=150 ALIGN=CENTER></APPLET>
Java Code
import java.awt.*;
public class FontTest extends java.applet.Applet {
String[] fontList;
public void init() {
fontList = Toolkit.getDefaultToolkit().getFontList();
}
public void paint(Graphics g) {
Font theFont;
FontMetrics fm;
int fontHeight = 0;
for (int i = 0; i < fontList.length; i++) {
theFont = new Font(fontList[i], Font.BOLD, 16);
g.setFont(theFont);
fm = getFontMetrics(theFont);
fontHeight += fm.getHeight();
g.drawString(fontList[i] + " 16 point Bold", 10, fontHeight);
}
}
}
|