import java.applet.*; import java.awt.*; import java.net.*; import java.util.*; import Clock; interface Countdown_action { abstract void countdown_action (); } public class Hello extends Applet implements Countdown_action { int clock_start_minutes=1, clock_start_seconds=20, clock_width=40*4+20, clock_height=80; Clock myclock; CardLayout mylayout; /* ** "init(), start(), stop(), destroy()" ** lifecycle method of class Applet. */ public synchronized void init() { String arg; // get parameters from applet tag fields arg = getParameter("clock_start_minutes"); if (arg != null) clock_start_minutes=Integer.parseInt(arg); arg = getParameter("clock_start_seconds"); if (arg != null) clock_start_seconds=Integer.parseInt(arg); arg = getParameter("clock_height"); if (arg != null) clock_height = Integer.parseInt(arg); arg = getParameter("clock_width"); if (arg != null) clock_width = Integer.parseInt(arg); myclock = new Clock(clock_start_minutes, clock_start_seconds, clock_width, clock_height, this); //setLayout(new FlowLayout(FlowLayout.CENTER)); setLayout(mylayout = new CardLayout()); add(myclock); repaint(); } public void countdown_action () { getAppletContext().showStatus("Count down finished"); remove((Component) myclock); requestFocus(); repaint(); myclock.clockthread.stop(); myclock = null; System.gc(); } public synchronized void start() { if (myclock.clockthread.isAlive()) myclock.clockthread.resume(); else myclock.clockthread.start(); } public void stop() { myclock.clockthread.suspend(); } public void destroy() { myclock.clockthread.stop(); } public void paint(Graphics g) { //Draw a Rectangle around the applet's display area. g.drawRect(0, 0, size().width-1, size().height-1); g.drawLine(0, 0, size().width-1, size().height-1); g.drawLine(size().width-1, 0, 0, size().height-1); } }