// Ausgabe der Zeit aus Tutorial

import java.awt.Graphics;
import java.util.*;
import java.text.DateFormat;
import java.applet.Applet;
import java.awt.Color;

public class DigitalUhr2 extends Applet implements Runnable 
{
private Thread clockThread = null;
              
public void init()
{
setBackground(Color.yellow);
}

public void start() 
{
if (clockThread == null) 
  {
  clockThread = new Thread(this, "Clock");
  clockThread.start();
   }
}

public void run() 
{
Thread myThread = Thread.currentThread();
while (clockThread == myThread) 
   {
    repaint();
    try 
      {
      Thread.sleep(1000);
      } 
     catch (InterruptedException e) 
        {            // the VM doesn't want us to sleep anymore,
                      // so get back to work
        }
   }
}

public void paint(Graphics g) 
{
// get the time and convert it to a date
Calendar cal = Calendar.getInstance();
Date date = cal.getTime();
// format it and display it
DateFormat dateFormatter = DateFormat.getTimeInstance();
g.drawString(dateFormatter.format(date), 10, 20);
}

// overrides Applet's stop method, not Thread's
public void stop() 
{
clockThread = null;
}

}

