importjava.awt.EventQueue;importjava.awt.event.ActionEvent;importjava.awt.event.ActionListener;importjava.text.SimpleDateFormat;importjava.util.Calendar;importjava.util.D...
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.Timer;
public class timetext {
private JFrame frame;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
timetext window = new timetext();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
public timetext() {
initialize();
}
private void initialize() {
frame = new JFrame();
frame.setBounds(100, 100, 450, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(null);
String s=String.format("%tY-%tm-%td %tH:%tM:%tS",new Date(),new Date(),new Date(),new Date(),new Date(),new Date());
JLabel lblNewLabel = new JLabel(s);
lblNewLabel.setBounds(158, 116, 137, 15);
frame.getContentPane().add(lblNewLabel);
frame.setVisible(true);
}
}
能够显示时间,怎么添加代码,使时间能动态显示,即每秒或每分更新一次
展开