Displaypublic class Display extends Frame
Fields Summary |
---|
static String[] | fonts | private Dimension | dim |
Constructors Summary |
---|
Display()
super ("Font Display");
fonts = Toolkit.getDefaultToolkit().getFontList();
|
Methods Summary |
---|
public void | addNotify()
Font f;
super.addNotify();
int height = 0;
int maxWidth = 0;
final int vMargin = 5, hMargin = 5;
for (int i=0;i<fonts.length;i++) {
f = new Font (fonts[i], Font.PLAIN, 12);
height += getHeight (f);
f = new Font (fonts[i], Font.BOLD, 12);
height += getHeight (f);
f = new Font (fonts[i], Font.ITALIC, 12);
height += getHeight (f);
f = new Font (fonts[i], Font.BOLD | Font.ITALIC, 12);
height += getHeight (f);
maxWidth = Math.max (maxWidth, getWidth (f, fonts[i] + " BOLDITALIC"));
}
Insets inset = insets();
dim = new Dimension (maxWidth + inset.left + inset.right + hMargin,
height + inset.top + inset.bottom + vMargin);
resize (dim);
| private int | getHeight(java.awt.Font f)
FontMetrics fm = Toolkit.getDefaultToolkit().getFontMetrics(f);
return fm.getHeight();
| private int | getWidth(java.awt.Font f, java.lang.String s)
FontMetrics fm = Toolkit.getDefaultToolkit().getFontMetrics(f);
return fm.stringWidth(s);
| public static void | main(java.lang.String[] args)
Display f = new Display();
f.show();
| public void | paint(java.awt.Graphics g)
g.translate(insets().left, insets().top);
int x = 0;
int y = 0;
for (int i=0;i<fonts.length;i++) {
Font plain = new Font (fonts[i], Font.PLAIN, 12);
Font bold = new Font (fonts[i], Font.BOLD, 12);
Font italic = new Font (fonts[i], Font.ITALIC, 12);
Font bolditalic = new Font (fonts[i], Font.BOLD | Font.ITALIC, 12);
g.setFont (plain);
y += getHeight (plain);
g.drawString (fonts[i] + " PLAIN", x, y);
g.setFont (bold);
y += getHeight (bold);
g.drawString (fonts[i] + " BOLD", x, y);
g.setFont (italic);
y += getHeight (italic);
g.drawString (fonts[i] + " ITALIC", x, y);
g.setFont (bolditalic);
y += getHeight (bolditalic);
g.drawString (fonts[i] + " BOLDITALIC", x, y);
}
resize (dim);
|
|