HTML
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); }); } }