System Clock Program in Java



import java.awt.*;
import java.awt.event.*;
import java.text.SimpleDateFormat;  
import java.util.Date;  
class SystemClock extends Frame
{
Label l,lt;

void initGUI()
{
setTitle("System Clock");
Font font = new Font("Times New Roman", Font.PLAIN, 20);
lt = new Label("Date & Time",Label.CENTER);
lt.setFont(font);
add(lt,BorderLayout.NORTH);

l = new Label("",Label.CENTER);
l.setFont(font);
add(l,BorderLayout.CENTER);
setSize(400,400);
setVisible(true);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent w)
{
System.exit(0);
}
});
while(true)
{
SimpleDateFormat formatter = new SimpleDateFormat("EEE, d MMM yyyy      h:mm:ss a");  
    Date date = new Date(); 
l.setText(formatter.format(date));
}
}
public SystemClock()
{
initGUI();
}
public static void main(String[] args) 
{
new SystemClock();
}
}


OUTPUT:-


System Clock

Comments

Popular posts from this blog

HOW TO SETUP CODE BLOCKS FOR GRAPHICS PROGRAMS

Smile emoji using graphics in Java using Applet