Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
240 views

Digital Clock Program in Java Using Applet

This document contains the code for a digital clock applet program written in Java. The applet uses threads to continuously repaint the clock display every second, showing the current date and time. It gets the current date and time from the system Calendar and Date objects, formats them, and draws the strings to the applet window using Graphics methods.

Uploaded by

kantgaurav
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
240 views

Digital Clock Program in Java Using Applet

This document contains the code for a digital clock applet program written in Java. The applet uses threads to continuously repaint the clock display every second, showing the current date and time. It gets the current date and time from the system Calendar and Date objects, formats them, and draws the strings to the applet window using Graphics methods.

Uploaded by

kantgaurav
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

/*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>*/

You might also like