欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Java動態(tài)顯示當(dāng)前日期和時(shí)間

 更新時(shí)間:2019年12月20日 16:21:01   作者:Bit0_1  
這篇文章主要為大家詳細(xì)介紹了Java動態(tài)顯示當(dāng)前日期和時(shí)間,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

Java 動態(tài)顯示當(dāng)前系統(tǒng)的日期、時(shí)間;如圖所示:

package com.xin.test;
 
import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.SimpleDateFormat;
import java.util.Date;
 
import javax.swing.JLabel;
import javax.swing.Timer;
import javax.swing.JFrame;
 
public class NowTime extends JFrame {
 
 
 private static final long serialVersionUID = 4306803332677233920L;
 
 // 添加 顯示時(shí)間的JLabel
 public NowTime() {
 JLabel time = new JLabel();
 time.setForeground(Color.BLUE);
 time.setBounds(30, 0, 900, 130);
 time.setFont(new Font("微軟雅黑", Font.BOLD, 80));
 this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 this.setLayout(null);
 this.setTitle("now time");
 this.setBounds(500, 200, 930, 200);
 this.setVisible(true);
 this.add(time);
 this.setTimer(time);
 }
 
 // 設(shè)置Timer 1000ms實(shí)現(xiàn)一次動作 實(shí)際是一個(gè)線程
 private void setTimer(JLabel time) {
 final JLabel varTime = time;
 Timer timeAction = new Timer(100, new ActionListener() {
  public void actionPerformed(ActionEvent e) {
  long timemillis = System.currentTimeMillis();
  // 轉(zhuǎn)換日期顯示格式
  SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  varTime.setText(df.format(new Date(timemillis)));
  }
 });
 timeAction.start();
 }
 
 // 運(yùn)行方法
 public static void main(String[] args) {
 new NowTime();
 }
 
}

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論