import java.awt.*;
import java.applet.*;
import java.util.*;
import java.text.*;

/* <applet code="AnalogClock" width="300" height="300">
   </applet>
*/

/* Copyright Samar Abbas, Sept. 11 2000
   http://www.geocities.com/samarstan   */

public class AnalogClock extends Applet implements Runnable
{
 Thread t;
 public void init()
 {
  String strings;
 }

 public void start()
 {
  t = new Thread(this);
  t.start();
 }


 public void paint(Graphics g)
 {
  setBackground(Color.black);
// Draw Circle center(125,125), radius 75
  g.setColor(Color.blue);
  g.fillOval(0,0,100,100);

// getSeconds() is obsolete in java.lang.Date()
// abstract Calendar cannot be instantiated
// Math.sin takes only radian as input not degrees
  Calendar cal = Calendar.getInstance();


  double secs = (double) cal.get( Calendar.SECOND);
    double s_rad = secs * ( 2 * Math.PI / 60 );
    double s_dx = Math.sin( s_rad ) * 50 ; 
    double s_dy = Math.cos( s_rad ) * 50 ; 
    System.out.println(" Secs are " + secs );
    g.setColor(Color.yellow);
  g.drawLine( 50, 50, 50 + (int)s_dx, 50 - (int)s_dy );

  double mins = (double) cal.get( Calendar.MINUTE);
    double m_rad = mins * ( 2 * Math.PI / 60 );
    double m_dx = Math.sin( m_rad ) * 40 ; 
    double m_dy = Math.cos( m_rad ) * 40 ; 
    System.out.println(" Mins are " + mins );
    g.setColor(Color.red);
  g.drawLine( 50, 50, 50 + (int)m_dx, 50 - (int)m_dy );



  double hours = (double) cal.get( Calendar.HOUR_OF_DAY);
    double h_rad = hours * ( 2 * Math.PI / 24 );
    double h_dx = Math.sin( h_rad ) * 30 ; 
    double h_dy = Math.cos( h_rad ) * 30 ; 
    System.out.println(" Hours are " + hours );
    g.setColor(Color.black);
  g.drawLine( 50, 50, 50 + (int)h_dx, 50 - (int)h_dy );



 }

 public void run()
 {
// without this the watch does not work
// remember which thread we are
  Thread ct = Thread.currentThread();
// the sleep should be in this loop otherwise repaint is too fast
  while (ct == t)
     {
     repaint();
     try{ 
        t.sleep(1000);
        }
     catch(InterruptedException e)
        { System.out.println("Interrupted"); }
     }
 }

public void update(Graphics g)
 { paint(g); }


 public void stop()
 {
  t = null;
 }


}


