Wednesday, April 2, 2014

Applet Program for clock

import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class clock extends Applet
{  
private Applet a=this;
private MyThread m;
private final double mf=3.14/180;
private int p=0,r=50,x=0,y=0;
public void init()
{  
setBackground(Color.pink);
//setBackground(Color.red);
setForeground(Color.blue);
// setSize(300,200);
}
public void start()
{

m=new MyThread();
m.start();
}
public void paint(Graphics g)
{  
    //System.out.println("x"+x);
    //System.out.println("y"+y);
    //g.setColor(Color.red);
//g.drawOval(100,50,100,100);
g.drawRoundRect(100,50,100,100,45,45);
g.drawLine(150,100,x+150,y+100);
}
class MyThread extends Thread
{
public void run()
{
while(true)
{
try{
Thread.sleep(1000);
}
catch(InterruptedException ie)
{

}
p+=6;
x=(int)(r*Math.cos(p*mf));
// System.out.println("x"+x);
y=(int)(r*Math.sin(p*mf));
// System.out.println("y"+y);
a.repaint();
}
}
}
}

No comments:

Post a Comment