Display a clock
using Applet
import java.awt.*;
import java.applet.*;
import java.applet.*;
import java.awt.*;
import java.util.*;
public class
ClockApplet extends Applet implements Runnable
{
Thread t,t1;
public void start()
{
t = new Thread(this);
t.start();
}
public void run()
{
t1 = Thread.currentThread();
while(t1 == t)
{
repaint();
try
{
t1.sleep(1000);
}
catch(InterruptedException e){}
}
}
public void paint(Graphics g)
{
Calendar cal = new GregorianCalendar();
String hour =
String.valueOf(cal.get(Calendar.Hour));
String minute =
String.valueOf(cal.get(Calendar.Minute));
String second =
String.valueOf(cal.get(Calendar.Second));
g.drawString(hour + ":" +
minute + ":" + second, 20, 30);
}
}
No comments:
Post a Comment