home *** CD-ROM | disk | FTP | other *** search
Java Source | 1998-03-05 | 1.5 KB | 56 lines |
- import java.awt.*;
-
- /** read fonts used by the browser and use the same ones
- */
- public class fontApplet extends java.applet.Applet
- {
- Font boldFont, bigBoldFont, smallBoldItalicFont;
-
- public void init() {
- Font browserFont = getFont();
- System.out.println("Browser font is "+browserFont);
- boldFont = new Font(browserFont.getName(), Font.BOLD, browserFont.getSize());
- bigBoldFont = new Font(browserFont.getName(), Font.BOLD, browserFont.getSize()+4);
- smallBoldItalicFont = new Font(browserFont.getName(), Font.BOLD+Font.ITALIC, browserFont.getSize()-4);
-
- }
-
- public void paint(Graphics g)
- {
- fm1 = g.getFontMetrics(boldFont);
- fm2 = g.getFontMetrics(bigBoldFont);
- fm3 = g.getFontMetrics(smallBoldItalicFont);
- String s1 = "Not a ";
- String s2 = "Hello, World";
- String s3 = " Program";
- int w1 = fm1.stringWidth(s1);
- int w2 = fm2.stringWidth(s2);
- int w3 = fm3.stringWidth(s3);
-
- Dimension d = size();
- Insets in = insets();
- int client_width = d.width - in.right - in.left;
- int client_height = d.height - in.bottom - in.top;
- int cx = (client_width - w1 - w2 - w3) / 2;
- int cy = client_height / 2;
- g.drawRect(0, 0, client_width - 1, client_height - 1);
-
- g.setFont(boldFont);
- g.drawString(s1, cx, cy);
- cx += w1;
- g.setFont(bigBoldFont);
- g.drawString(s2, cx, cy);
- cx += w2;
- g.setFont(smallBoldItalicFont);
- g.drawString(s3, cx, cy);
- }
-
-
- private FontMetrics fm1, fm2, fm3;
-
- }
-
-
-
-
-