import java.awt.*; import java.applet.*; public class FontMetricsApplet extends Applet { public void paint(Graphics g) { FontMetrics fm = g.getFontMetrics(); g.setColor(Color.BLACK); // first set y to the first line that will be on-screen int y = fm.getHeight(); // draw a line of text there g.drawString("Hello World",10,y); // center a line of text String str = "Hello World Centered"; int x = (getWidth()/2)-(fm.stringWidth(str)/2); y+=fm.getHeight();// move down one line of text g.drawString(str,x,y); } }