FileDocCategorySizeDatePackage
Clock.javaAPI DocExample1545Tue Apr 03 17:42:34 BST 2001None

Clock

public class Clock extends Applet

Fields Summary
private int
x_middle
private int
y_middle
private int
length
private double
degrees_to_radians
Constructors Summary
Methods Summary
public voidpaint(java.awt.Graphics g)

	   // middle of the canvas,
	   // can be found as follows=>
	   // x_middle = getSize().width / 2;
	   // y_middle = getSize().height/ 2;
	   // length   = getSize().width / 2 - 1;  //Choose a length for the pendulum
	   x_middle = 150;
	   y_middle = 150;
	   length   = 149;
	   degrees_to_radians = 3.14159 / 180.0;
	   // sin and cos work in units
	   // called RADIANS which are different from degrees.
	   // Basically there are 2 times pi of them (or 6.28) in 360 degrees
	   // which is a full circle.
	   // Draw a big circle
	   g.drawOval(0,0,299,299);
      // Step the second hand through 360 degrees in 5 degree steps
      for (int angle = 0 ; angle < 360; angle = angle + 5 )
	   {
	       // Draw second hand 
          g.drawLine(x_middle , y_middle ,
                     x_middle+(int)(Math.cos((double)angle*degrees_to_radians)*length),
                     y_middle+(int)(Math.sin((double)angle*degrees_to_radians)*length));
          // put the delay loop here
     		
	   } // end of for loop