Tuesday, 12 April 2016

Digital Clock



import java.util.*;
import javax.swing.*;
import java.awt.event.*;
import java.text.*;
public class DigitalClock extends JFrame
{
JButton jb;
String timeupdated="";
DigitalClock()
{
jb=new JButton();
setSize(400,400);
add(jb);
setVisible(true);
while(true)
{
Date time=new Date();
SimpleDateFormat formatter=new SimpleDateFormat("hh:mm:ss");
timeupdated=formatter.format(time);
printable();
try
{
Thread.sleep(1000);
}
catch(Exception e)
{
System.out.println(e);
}
}
}

public void printable()
{
jb.setText(timeupdated);
}
public static void main(String args[])
{
DigitalClock dc=new DigitalClock();
}
}


No comments:

Post a Comment