This is a java program to display Digital clock in an applet
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.util.*;
/*
<applet code="DigiClock"
width=400
height=300
>
</applet>
*/
public class DigiClock extends Applet implements Runnable
{
public Date d;
Thread t;
public void init()
{
d=new Date();
Font f=new Font("casteller",Font.ITALIC,56);
setFont(f);
t=new Thread(this);
t.start();
}
public void run()
{
repaint();
while(true)
import java.awt.event.*;
import java.applet.*;
import java.util.*;
/*
<applet code="DigiClock"
width=400
height=300
>
</applet>
*/
public class DigiClock extends Applet implements Runnable
{
public Date d;
Thread t;
public void init()
{
d=new Date();
Font f=new Font("casteller",Font.ITALIC,56);
setFont(f);
t=new Thread(this);
t.start();
}
public void run()
{
repaint();
while(true)
{
try
{
Thread.sleep(1000);
}
catch(Exception e)
{}
repaint();
}
}
public void paint(Graphics g)
{
d=new Date();
int hh=d.getHours();
hh%=12;
int mm=d.getMinutes();
int ss=d.getSeconds();
g.drawString(hh+":"+mm+":"+ss,100,150);
}
}
Output
Digital clock java applet |
No comments:
Post a Comment