Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package learning;
- /**
- *
- * @author lantisse
- */
- import java.awt.Font;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.text.SimpleDateFormat;
- import java.util.Date;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import javax.swing.Timer;
- public class DigitalClock extends JFrame implements ActionListener {
- JLabel timeLabel = new JLabel();
- SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
- Timer timer;
- public DigitalClock() {
- super("Tes");
- this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- timeLabel.setText(sdf.format(new Date(System.currentTimeMillis())));
- timeLabel.setFont(new Font("Proxima Nova Alt", Font.PLAIN, 24));
- timer = new Timer(500, this);
- timer.setRepeats(true);
- timer.start();
- this.add(timeLabel);
- this.pack();
- this.setVisible(true);
- }
- @Override
- public void actionPerformed(ActionEvent e) {
- if (e.getSource().equals(timer)) {
- // Then set a new time.
- timeLabel.setText(sdf.format(new Date(System.currentTimeMillis())));
- }
- }
- public static void main(String[] args) {
- // Create the digital clock.
- new DigitalClock();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement