/*
    This class is a basic extension of the Applet class.  It would generally be
    used as the main class with a Java browser or the AppletViewer.  But an instance
    can be added to a subclass of Container.  To use this applet with a browser or
    the AppletViewer, create an html file with the following code:

    <HTML>
    <HEAD>
    <TITLE> A simple program </TITLE>
    </HEAD>
    <BODY>
                                     200         50
    <APPLET CODE="Clock.class" WIDTH=332 HEIGHT=169></APPLET>

    </BODY>

    </HTML>

    You can add controls to Clock with Cafe Studio.
    (Menus can be added only to subclasses of Frame.)
 */

import java.awt.*;
import java.applet.*;

//My code starts here
import java.util.Date;
//My code ends here

public class Clock extends Applet implements Runnable {


    //My code starts here
    Font theFont = new Font("Verdana", Font.PLAIN,12);
    Date theDate;
    Thread runner;
    //My code ends here

    public void init() {

        super.init();

        //{{INIT_CONTROLS
        setLayout(null);
        resize(230,190);

        //My code starts here
        //label1=new Label("A Simple Applet");
        //add(label1);
        //label1.reshape(61,73,98,15);
        //}}
        //My code ends here

    }

    //My code starts here
    public void start() {
            if (runner == null); {
                runner = new Thread(this);
                runner.start();
            }
    }

    public void stop() {
            if (runner != null) {
                runner.stop();
                runner = null;
            }
    }

    public void run() {
            while (true) {
                theDate = new Date();
                repaint();
                try { Thread.sleep(1000); }
                catch (InterruptedException e) { }
            }
    }

   public void paint(Graphics g) {
            g.setFont(theFont);
            g.drawString(theDate.toString(), 10, 10); // was 10, 50 
    }
    //My code ends here

    public boolean handleEvent(Event event) {
        return super.handleEvent(event);
    }

    //{{DECLARE_CONTROLS
    Label label1;
    //}}

}
