import java.awt.Graphics; import java.awt.Font; //clases importadas import java.util.Date; //declaracion del applet, el subproceso(runnable) y las variables public class DigitalClock extends java.applet.Applet implements Runnable { Font theFont = new Font("TimesRoman",Font.BOLD,24); Date theDate; Thread runner; //iniciamos el reloj para mostrar su hora public void start() { if (runner == null) { runner = new Thread(this); runner.start(); } } //paramos el reloj despues de mostrar la hora public void stop() { if (runner != null) { runner = null; } } //lo que de hace el applet: public void run() { Thread thisThread = Thread.currentThread(); while (runner == thisThread) { repaint(); try { Thread.sleep(1000); } catch (InterruptedException e) {} } } public void paint(Graphics screen) { theDate = new Date(); screen.setFont(theFont); screen.drawString("" + theDate.toString(), 10, 50); } }