import java.applet.Applet;
import java.awt.*;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
/**
* Created by : Amar Ghugare
* created on : 21-05-2022 19:15
* Purpose of class :
*/
public class Slip8Q2 extends Applet implements Runnable {
Thread t1 = null;
int hours = 0, minutes = 0, seconds = 0;
String time = "";
public void init() {
setBackground( Color.green);
}
public void start() {
t1 = new Thread( this );
t1.start();
}
public void run() {
try {
while (true) {
Calendar cal = Calendar.getInstance();
hours = cal.get( Calendar.HOUR_OF_DAY );
if ( hours > 12 ) hours -= 12;
minutes = cal.get( Calendar.MINUTE );
seconds = cal.get( Calendar.SECOND );
SimpleDateFormat formatter = new SimpleDateFormat("hh:mm:ss");
Date d = cal.getTime();
time = formatter.format( d );
repaint();
Thread.sleep( 1000 );
}
}
catch (Exception ignored) { }
}
public void paint( Graphics g ) {
g.setColor( Color.blue );
g.setFont(new Font("",Font.PLAIN,100));
g.drawString( time, 100, 150 );
}
}
/*<applet code= "Slip8Q2.class" height="300" width="600"></applet>*/
No comments:
Post a Comment