1  // File:  Centered.java
  2  
  3  import java.awt.*;
  4  
  5  public class Centered extends java.applet.Applet
  6  {
  7    public void paint (Graphics g)
  8    {
  9      Font f = new Font("TimesRoman", Font.PLAIN, 24);
 10      FontMetrics fm = getFontMetrics(f);
 11      String s = "Today is your lucky day.";
 12  
 13      setBackground(Color.cyan);
 14      g.setFont(f);
 15      int xstart = (getSize().width - fm.stringWidth(s))/2;
 16      int ystart = ((getSize().height - fm.getHeight())/2)
 17  		+ fm.getAscent() + fm.getLeading();
 18      g.drawString (s, xstart, ystart);
 19    }
 20  }