APPLET DIGITAL CLOCK:
import
java.applet.*;
import
java.awt.*;
import
java.util.*;
import
java.text.*;
public class AppletDigitalClock
extends Applet implements Runnable {
Thread th = null;
int hours=0, minutes=0, seconds=0, miliSeconds=0;
java.lang.String timeString = “”;
public void init() {
setBackground( Color.white);
}
public void start() {
th = new Thread( this );
th.start();
}
public void run() {
try {
while (true) {
Calendar calndr = Calendar.getInstance();
hours = calndr.get( Calendar.HOUR_OF_DAY );
if ( hours > 12 ) hours -= 12;
minutes = calndr.get( Calendar.MINUTE );
seconds = calndr.get( Calendar.SECOND );
miliSeconds=calndr.get(Calendar.MILLISECOND);
SimpleDateFormat formatter = new SimpleDateFormat(“hh:mm:ss:ms”);
Date date = calndr.getTime();
timeString = formatter.format( date );
repaint();
th.sleep( 1000 );
}
}
catch (Exception e) { }
}
public void paint( Graphics g ) {
g.setColor( Color.red );
g.drawString( timeString, 60,
100 );
}
}
OUTPUT: