Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.Timer;

public class Main extends JFrame {
    public static Timer t;
    public JLabel jlabel4 = new JLabel();

    public Main() {
        this.setLayout(null);
        jlabel4.setBounds(0, 0, 100, 30);
        this.add(jlabel4);
        this.pack();
        t = new Timer(1000, new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                jlabel4.setText(new SimpleDateFormat("HH:mm:ss", Locale.FRANCE).format(new Date()));
            }
        });
        t.start();
        setSize(new Dimension(200, 60));
        setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    }

    public static void main(String[] args) {
        new Main().setVisible(true);
    }
}