public class Output extends javax.swing.JFrame {
public Output() {
initComponents();
setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource("abc.jpg")));
setSize(400, 700);
setLocationRelativeTo(null);
setResizable(false);
setdate();
}
public void setdate(){
ActionListener obj = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
java.util.Date date = new Date();
Date.setText(date.getDate()+"-"+(1+date.getMonth())+
"-"+date.getYear()+"/"+date.getHours() + ":"
+ date.getMinutes()+ ":" +
date.getSeconds());
}
};
new javax.swing.Timer(1000,obj).start();
}
每當我運行此代碼,我得到的每一件事情確定,但同時設定年復一年它顯示18-8-116
,而它應該顯示18-8-16
或18-8-2016
。在GUI沒有顯示正確的一年
您使用的是舊的麻煩類現在['java.time.LocalDate']取代(http://docs.oracle.com /javase/8/docs/api/java/time/LocalDate.html)。而是調用['LocalDate.of(int year,int month,int dayOfMonth)'](http://docs.oracle.com/javase/8/docs/api/java/time/LocalDate.html#of-int- INT-內部 - )。沒有時髦指望這個班; 2016年應該是'2016'。 –