Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Date;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
import javax.swing.Timer;

public class Main {
    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                final Date date = new Date();
                final JLabel timeLabel = new JLabel(date.toString());
                Timer timer = new Timer(1000, new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                        date.setTime(System.currentTimeMillis());
                        timeLabel.setText(date.toString());
                    }
                });
                timer.start();
                JOptionPane.showMessageDialog(null, timeLabel);
            }
        });
    }
}