最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

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

Java 動(dòng)態(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)一次動(dòng)作 實(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();
 }
 
}

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

相關(guān)文章

最新評(píng)論

错那县| 上思县| 舒城县| 岐山县| 洪泽县| 鹿邑县| 城固县| 沁水县| 柘荣县| 三门峡市| 台安县| 临沭县| 揭东县| 易门县| 唐山市| 山东| 四子王旗| 海宁市| 旌德县| 玉门市| 安顺市| 天峨县| 潢川县| 乐昌市| 广水市| 无锡市| 克东县| 苗栗县| 囊谦县| 上林县| 兴仁县| 永泰县| 都安| 双牌县| 含山县| 兰州市| 海丰县| 东阳市| 志丹县| 勃利县| 边坝县|