// File: Centered.java import java.awt.*; public class Centered extends java.applet.Applet { public void paint (Graphics g) { Font f = new Font("TimesRoman", Font.PLAIN, 24); FontMetrics fm = getFontMetrics(f); String s = "Today is your lucky day."; setBackground(Color.cyan); g.setFont(f); int xstart = (getSize().width - fm.stringWidth(s))/2; int ystart = ((getSize().height - fm.getHeight())/2) + fm.getAscent() + fm.getLeading(); g.drawString (s, xstart, ystart); } }