Java Code For Live Date and Time
import java.awt.Font;
import javax.swing.JFrame; import javax.swing.JLabel; public class LiveDateTime { public static void main(String[] args) { JFrame frame = new JFrame("Live Date and Time"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(400, 200); JLabel dateTimeLabel = new JLabel(); dateTimeLabel.setFont(new Font("Arial", Font.BOLD, 24)); frame.add(dateTimeLabel); frame.setVisible(true); while (true) { String dateTime = java.time.LocalDateTime.now().toString(); dateTimeLabel.setText(dateTime); try { Thread.sleep(1000); // Update every second } catch (InterruptedException e) { e.printStackTrace(); } } } }
0 Reviews:
Post a Comment