Notification texts go here Contact Us Click here

Using Java to program Digital clock .

Please wait 0 seconds...
Scroll Down and click on Go to Link for destination
Congrats! Link is Generated



import javax.swing.*;
import java.awt.*;
import java.text.SimpleDateFormat;
import java.util.Date;
 
public class DigitalClockApp extends JFrame {
    private JLabel timeLabel;
 
    public DigitalClockApp() {
        setTitle("Digital Clock");
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setSize(200, 100);
        setLocationRelativeTo(null);
 
        // Create the time label
        timeLabel = new JLabel();
        timeLabel.setFont(new Font("Arial", Font.BOLD, 24));
        timeLabel.setHorizontalAlignment(SwingConstants.CENTER);
        updateTime();
 
        // Set the time label as the content pane
        setContentPane(timeLabel);
 
        // Start a timer to update the time every second
        Timer timer = new Timer(1000, e -> updateTime());
        timer.start();
    }
 
    private void updateTime() {
        SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
        String time = dateFormat.format(new Date());
        timeLabel.setText(time);
    }
 
    public static void main(String[] args) {
        SwingUtilities.invokeLater(() -> {
            DigitalClockApp app = new DigitalClockApp();
            app.setVisible(true);
        });
    }
}
 

Post a Comment

Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.