How to create Java Digital clock using Swing

How to create Java Digital clock using Swing

How to create Java Digital clock using Swing
Below java code will create a Digital Java clock using swing components which include JButton, JFrame etc.

import java.awt.Color;
import java.awt.Font;
import java.text.SimpleDateFormat;
import javax.swing.JButton;
import javax.swing.JFrame;
import java.util.Calendar;
import java.util.Date;
import javax.swing.UIManager;


public class JavaDigitalClock  extends JFrame implements Runnable{
    Thread thread=null;
    int hours=0, minutes=0, seconds=0;
    String timeString = "";
    JButton button;

    JavaDigitalClock()
    {
        super("Java Digital clock Example");
        try{
            UIManager.setLookAndFeel
                    ("com.sun.java.swing.plaf.windows.WindowsClassicLookAndFeel");
        }
        catch(Exception e){e.printStackTrace();}

        button=new JButton();

        thread = new Thread(this);
        thread.start();

        button=new JButton();
        button.setBounds(50,50,00,50);
        button.setBackground(Color.BLACK);
        button.setForeground(Color.WHITE);
        button.setFont(new Font("Times New Roman",Font.BOLD,20));
        add(button);
        setSize(300,400);
        setLocationRelativeTo(null);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setLayout(null);
        setVisible(true);

    }

    @Override
    public void run() {
        try {
            while (true) {

                Calendar calendar = Calendar.getInstance();
                hours = calendar.get( Calendar.HOUR_OF_DAY );
                if ( hours > 12 ) hours -= 12;
                minutes = calendar.get( Calendar.MINUTE );
                seconds = calendar.get( Calendar.SECOND );

                SimpleDateFormat formatter = new SimpleDateFormat("hh:mm:ss");
                Date date = calendar.getTime();
                timeString = formatter.format( date );

                showTime();

                thread.sleep( 1000 );  // interval given in milliseconds              }
        }
        catch (Exception e) { }

    }
    public void showTime()
    {
        button.setText(timeString);
    }
    public static void main(String args[])
    {
        new JavaDigitalClock();
    }
}

COMMENTS

Name

android android Apps android emulators antivirus blogger bluestack Break Statement in Java constructors download downloader drivers emulators java java control statements java do-while loop java for loop java infinitive do-while loop java system methods java tutorials Java While Loop java.awt java.swing javalookandfeel javascript JButton JCheckBox JColorChooser JComboBox JDialog JFileChooser JFrame JLayeredPane JList JMenuBar joomla JOptionPane JPanel JPasswordField JPopupMenu JProgressBar JRadioButton JScrollBar JSlider JSpinner JTabbedPane JTable JTextArea JTextField JToolBar mysql php plugins Polymorphism setToolTiptext skype for windows software swing class themes Visual Studio Code WeChat whatsapp wordpress
false
ltr
item
Java Codes: How to create Java Digital clock using Swing
How to create Java Digital clock using Swing
How to create Java Digital clock using Swing
https://3.bp.blogspot.com/-pxLKoMxouNg/WPpOygH1joI/AAAAAAAAHuA/oaDesEfD2FU69mR-PHLn9q9J-XoVToDKgCLcB/s1600/how-create-Java-Digital-clock-using-Swing.PNG
https://3.bp.blogspot.com/-pxLKoMxouNg/WPpOygH1joI/AAAAAAAAHuA/oaDesEfD2FU69mR-PHLn9q9J-XoVToDKgCLcB/s72-c/how-create-Java-Digital-clock-using-Swing.PNG
Java Codes
http://www.download-all.net/2017/04/how-to-create-java-digital-clock-using.html
http://www.download-all.net/
http://www.download-all.net/
http://www.download-all.net/2017/04/how-to-create-java-digital-clock-using.html
true
7826648292785071009
UTF-8
Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS CONTENT IS PREMIUM Please share to unlock Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy