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

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

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

public class GrandClock 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.magenta);
// Draw the Case of the Clock
 g.setColor(Color.black);
   g.fillRect(30,30,190,190);

// Draw white rectangle left hand corner 50,50, 150 pixels wide
 g.setColor(Color.white);
   g.fillRect(50,50,150,150);

// Draw invisble Circle center(125,125), radius 75
 g.setColor(Color.white);
   g.drawOval(50,50,150,150);
 g.setColor(Color.black);
   g.drawString("IX", 60, 125);
   g.drawString("XII", 120, 70);
   g.drawString("III", 185, 125);
   g.drawString("VI", 125, 190);

// 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 ) * 75 ; 
   double s_dy = Math.cos( s_rad ) * 75 ; 
   System.out.println(" Secs are " + secs );
   g.setColor(Color.black);
 g.drawLine( 125, 125, 125 + (int)s_dx, 125 - (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 ) * 60 ; 
   double m_dy = Math.cos( m_rad ) * 60 ; 
   System.out.println(" Mins are " + mins );
   g.setColor(Color.black);
 g.drawLine( 125, 125, 125 + (int)m_dx, 125 - (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 ) * 40 ; 
   double h_dy = Math.cos( h_rad ) * 40 ; 
   System.out.println(" Hours are " + hours );
   g.setColor(Color.black);
 g.drawLine( 125, 125, 125 + (int)h_dx, 125 - (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;
 }

}

