Here's how to center a string s horizontally in the applet window: int appletWidth = getSize().width; FontMetrics fm = g.getFontMetrics(); int stringWidth = fm.stringWidth( s ); int x = (appletWidth - stringWidth)/2; g.drawString( s, x, y ); where y is arbitrary (to center the string vertically, we have to work a bit harder... ) |