//File: Surprise.java import java.awt.*; import java.awt.event.*; import java.applet.*; public class Surprise extends Applet { // Surprise with an exploding balloon // Author: Rachel McDermott, September 27, 1996 public void paint (Graphics g) { Dimension size = getSize(); int diameter = 0, w = size.width, h = size.height, cmin = (int)Math.min(w, h); g.setColor(Color.yellow); while (diameter < cmin) { g.fillOval((w-diameter)/2, (h-diameter)/2, diameter, diameter); diameter++; try { Thread.sleep(10); // sleep for 10 msec } catch (InterruptedException t) { } } Font current = getFont(); FontMetrics metrics = getFontMetrics (current); int ws = metrics.stringWidth("Surprise!"); int hf = metrics.getHeight(); g.setColor(Color.red); g.drawString("Surprise!", (w-ws)/2, (h+hf)/2); } }