import static java.awt.Frame.MAXIMIZED_BOTH;
import java.text.SimpleDateFormat;
import java.util.GregorianCalendar;
import java.util.Locale;
import javax.swing.JFrame;
import static javax.swing.JFrame.EXIT_ON_CLOSE;
import javax.swing.JLabel;
import javax.swing.JPanel;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
public class TelaSistema extends JFrame {
public JLabel label = new JLabel();
public JPanel painel = new JPanel();
public TelaSistema() {
setExtendedState(MAXIMIZED_BOTH);
setTitle("Teste");
DateTimeFormatter fmt = DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm:ss");
LocalDateTime timePoint = LocalDateTime.now();
label = new JLabel(timePoint.format(fmt));
painel.add(label);
add(painel);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);
}
public static void main(String[] args) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
-> new TelaSistema();
}
});
}
}
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import javax.swing.JLabel;
import javax.swing.Timer;
public class ClockLabel extends JLabel implements ActionListener {
public ClockLabel() {
Timer t = new Timer(1000, thise -> setText(getDateTime()));
t.startsetInitialDelay(0);
setText(getDateTime t.start());
}
private String getDateTime() {
return LocalDateTime.now().format(DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm:ss"));
}
@Override
public void actionPerformed(ActionEvent ae) {
setText(getDateTime());
}
}