Digital Clock Program in Java Using Applet
Digital Clock Program in Java Using Applet
*/
import java.applet.*; import java.awt.*; import java.net.*; import java.util.*; import java.util.TimeZone ; import java.text.DateFormat ;
public class DigitalClock extends Applet implements Runnable { private Thread ct = null ; public void start() { if(ct == null) { ct = new Thread(this , "DigitalClock"); ct.start(); } } public void run(){ Thread mt = Thread.currentThread(); while ((ct == mt)) { repaint(); try{ Thread.sleep(1000);
} catch(InterruptedException e){} } } public void paint(Graphics g) { Calendar cal = Calendar.getInstance() ; Date ddd = new Date(); String dtd = ddd.toLocaleString(); int i = dtd.length(); int k = i - 10 ; String dt = dtd.substring(k,i); Date date = cal.getTime(); DateFormat dd = DateFormat.getDateInstance(DateFormat.LONG); DateFormat df = DateFormat.getTimeInstance(); g.setFont(new Font("Arial",Font.BOLD,15)); g.setColor(Color.magenta); g.drawString(dd.format(date),8,18); g.drawString(dt,16,38); } public void stop() { ct = null ; } } /*<applet code=DigitalClock height=500 width=500> </applet>*/