I would like to know how to display the current date and time of the computer, and the time must be updated at run time. I thought of passing an object to a label, but it did not. I will not save that date, I just want it to be displayed, I wanted to put it in a label so I can position it anywhere later.
package teste;
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;
public class TelaSistema extends JFrame {
public JLabel label = new JLabel();
public JPanel painel = new JPanel();
public TelaSistema() {
setExtendedState(MAXIMIZED_BOTH);
setTitle("Teste");
GregorianCalendar calendar = new GregorianCalendar();
label = new JLabel("Data aqui");
painel.add(label);
add(painel);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);
}
public static void main(String args[]) {
TelaSistema tela = new TelaSistema();
}
}