[ Home | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 ]

Exercise 10: Playing with Text

under construction ...

( You need to enable Java to see this applet. )

   Font font = new Font( "Monospaced", Font.PLAIN, 12 );

   Graphics g;
   g.setFont( font );

   FontMetrics fm = getFontMetrics( font );

   int charWidth = fm.charWidth('W');
   int charHeight = fm.getHeight();

   String s = "whatever";
   int stringWidth = fm.stringWidth( s );