import java.util.*;
import java.awt.*;
import java.applet.*;
public class MyClock extends Applet implements Runnable
{
Thread t;
int hh,mm,ss;
Font myf=new Font("Arial",Font.BOLD,50);
public void init()
{
t=new Thread(this);
t.start();
}
public void run()
{
for(;;)
{
Calendar tm=Calendar.getInstance();
hh=tm.get(Calendar.HOUR);
mm=tm.get(Calendar.MINUTE);
ss=tm.get(Calendar.SECOND);
try
{
t.sleep(1000);
repaint();
}
catch(Exception e)
{
}
}
}
public void paint(Graphics s)
{
String now="";
s.setColor(Color.BLUE);
s.setFont(myf);
now=String.valueOf(hh)+":"+String.valueOf(mm)+":"+String.valueOf(ss);
s.drawString(now,100,100);
}
}
No comments:
Post a Comment