import javax.swing.*;
import java.awt.*;
import java.text.SimpleDateFormat;
import java.util.Date;
public class DigitalClock extends JFrame {
private JLabel timeLabel;
public DigitalClock() {
setTitle("Digital Clock");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(300, 100);
// Create a label to display the time
timeLabel = new JLabel();
timeLabel.setHorizontalAlignment(JLabel.CENTER);
timeLabel.setFont(new Font("Arial", Font.PLAIN, 24));
// Add the label to the frame
add(timeLabel);
// Set up a timer to update the time every second
Timer timer = new Timer(1000, e -> updateClock());
timer.start();
}
private void updateClock() {
// Get the current time
Date now = new Date();
SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
String timeStr = dateFormat.format(now);
// Update the label with the current time
timeLabel.setText(timeStr);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(() -> {
DigitalClock clock = new DigitalClock();
clock.setLocationRelativeTo(null); // Center the frame on the screen
clock.setVisible(true);
});
}
}
Esterification Test Carboxylic Acid: Alcohol: Run Esterification
মন্তব্যসমূহ
একটি মন্তব্য পোস্ট করুন