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

Java實(shí)現(xiàn)動(dòng)態(tài)數(shù)字時(shí)鐘

 更新時(shí)間:2019年12月20日 15:10:55   作者:_yuanhao  
這篇文章主要為大家詳細(xì)介紹了Java實(shí)現(xiàn)動(dòng)態(tài)數(shù)字時(shí)鐘,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了Java實(shí)現(xiàn)動(dòng)態(tài)數(shù)字時(shí)鐘的具體代碼,供大家參考,具體內(nèi)容如下

構(gòu)建:

Clock繼承 JFrame 為運(yùn)行頁(yè)面
ClockText 測(cè)試類(lèi) 創(chuàng)建 Clock 對(duì)象 

運(yùn)行效果:

具體實(shí)現(xiàn):

一、Clock類(lèi)

  • 四個(gè)JPnal 三個(gè)放時(shí)間 最后一個(gè)放日期
  • 放時(shí)間的三個(gè)JPnal 分別加入 地點(diǎn) 時(shí)間 按鈕
  • 最后一個(gè)按鈕添加日期

具體實(shí)現(xiàn)如下:

public class Clock extends JFrame {
 private JPanel jPanelBeijing;
 private JPanel jPanelNewYork;
 private JPanel jPanelLondom;
 private JPanel jPanelDate;
 
 private boolean BeijingThreadFlag_IsStart = true;
 private boolean NewYorkThreadFlag_IsStart = true;
 private boolean LondonThreadFlag_IsStart = true;
 
 public Clock() {
 // TODO Auto-generated constructor stub
 jPanelBeijing = new JPanel();
 jPanelNewYork = new JPanel();
 jPanelLondom = new JPanel();
 jPanelDate = new JPanel();
 
 iniRelations();
 iniLayout();
 jFrameClick();
 
 setVisible(true);
 setSize(480, 225);
 setLocationRelativeTo(null);
 }
 
 private void iniLayout() {
 jPanelBeijing.setLayout(new GridLayout(3, 1));
 jPanelNewYork.setLayout(new GridLayout(3, 1));
 jPanelLondom.setLayout(new GridLayout(3, 1));
 }
 
 // 關(guān)系
 private void iniRelations() {
 this.add(BorderLayout.WEST, jPanelBeijing);
 this.add(BorderLayout.CENTER, jPanelNewYork);
 this.add(BorderLayout.EAST, jPanelLondom);
 this.add(BorderLayout.SOUTH, jPanelDate);
 Font placeFont = new Font("楷體", Font.BOLD, 36);
 JLabel jLabelBeijing = new JLabel("北京時(shí)間");
 jLabelBeijing.setFont(placeFont);
 jPanelBeijing.add(jLabelBeijing);
 setWestPanel();
 JLabel jLabelNewYork = new JLabel("紐約時(shí)間");
 jLabelNewYork.setFont(placeFont);
 jPanelNewYork.add(jLabelNewYork);
 setCenterPanel();
 JLabel jLabelLondon = new JLabel("倫敦時(shí)間");
 jLabelLondon.setFont(placeFont);
 jPanelLondom.add(jLabelLondon);
 setEastPanel();
 setDatePanel();
 }
 
 private void setWestPanel() {
 // add time for SouthPanel
 JLabel jLabelTime = new JLabel("加載中.");
 jLabelTime.setFont(new Font("宋體", Font.BOLD, 30));
 Timer timeAction = new Timer(1000, new ActionListener() {
 
  public void actionPerformed(ActionEvent e) {
  long timemillis = System.currentTimeMillis();
  // 轉(zhuǎn)換日期顯示格式
  SimpleDateFormat time = new SimpleDateFormat("HH:mm:ss ");
  jLabelTime.setText(time.format(new Date(timemillis)));
  }
 });
 timeAction.start();
 jPanelBeijing.add(jLabelTime);
 
 Button button = new Button("北京暫停");
 button.addActionListener(new ActionListener() {
 
  @Override
  public void actionPerformed(ActionEvent e) {
  // TODO Auto-generated method stub
  if (BeijingThreadFlag_IsStart) {
   timeAction.stop();
   button.setLabel("北京繼續(xù)");
   BeijingThreadFlag_IsStart = false;
  } else {
   timeAction.start();
   button.setLabel("北京暫停");
   BeijingThreadFlag_IsStart = true ;
  }
  }
 });
 jPanelBeijing.add(button);
 }
 
 private void setCenterPanel() {
 // add time for SouthPanel
 JLabel jLabelTime = new JLabel("加載中.");
 jLabelTime.setFont(new Font("宋體", Font.BOLD, 30));
 Timer timeAction = new Timer(1000, new ActionListener() {
 
  public void actionPerformed(ActionEvent e) {
  long timemillis = System.currentTimeMillis();
  // 轉(zhuǎn)換日期顯示格式
  SimpleDateFormat time = new SimpleDateFormat("HH:mm:ss ");
  jLabelTime.setText(time.format(new Date(timemillis - 13 * 60 * 60 * 1000)));
  }
 });
 timeAction.start();
 jPanelNewYork.add(jLabelTime);
 
 Button button = new Button("紐約暫停");
 button.addActionListener(new ActionListener() {
 
  @Override
  public void actionPerformed(ActionEvent e) {
  // TODO Auto-generated method stub
  if (NewYorkThreadFlag_IsStart) {
   timeAction.stop();
   button.setLabel("紐約繼續(xù)");
   NewYorkThreadFlag_IsStart = false;
  } else {
   timeAction.start();
   button.setLabel("紐約暫停");
   NewYorkThreadFlag_IsStart = true ;
  }
  }
 });
 jPanelNewYork.add(button);
 }
 
 private void setEastPanel() {
 // add time for SouthPanel
 // JLabel jLabelDate = new JLabel("Date");
 JLabel jLabelTime = new JLabel("加載中.");
 jLabelTime.setFont(new Font("宋體", Font.BOLD, 30));
 Timer timeAction = new Timer(1000, new ActionListener() {
 
  public void actionPerformed(ActionEvent e) {
  long timemillis = System.currentTimeMillis();
  // SimpleDateFormat date = new SimpleDateFormat("yyyy 年 MM 月 dd
  // 日 ");
  // jLabelDate.setText(" 當(dāng)前日期: " + date.format(new
  // Date(timemillis)));
  SimpleDateFormat time = new SimpleDateFormat("HH:mm:ss ");
  jLabelTime.setText(time.format(new Time(timemillis - 8 * 60 * 60 * 1000)));
  }
 });
 timeAction.start();
 jPanelLondom.add(jLabelTime);
 
 Button button = new Button("倫敦暫停");
 button.addActionListener(new ActionListener() {
 
  @Override
  public void actionPerformed(ActionEvent e) {
  // TODO Auto-generated method stub
  if (LondonThreadFlag_IsStart) {
   timeAction.stop();
   button.setLabel("倫敦繼續(xù)");
   LondonThreadFlag_IsStart = false;
  } else {
   timeAction.start();
   button.setLabel("倫敦暫停");
   LondonThreadFlag_IsStart = true ;
  }
  }
 });
 jPanelLondom.add(button);
 // jPanelLondom.add(jLabelDate);
 }
 
 private void setDatePanel() {
 // add time for SouthPanel
 JLabel jLabelDate = new JLabel("加載中.");
 Timer timeAction = new Timer(1000, new ActionListener() {
 
  public void actionPerformed(ActionEvent e) {
  long timemillis = System.currentTimeMillis();
   SimpleDateFormat date = new SimpleDateFormat("yyyy 年 MM 月 dd 日 ");
   jLabelDate.setText(" 當(dāng)前日期: " + date.format(new Date(timemillis)));
  }
 });
 timeAction.start();
 jPanelDate.add(jLabelDate);
 }
 
 private void jFrameClick(){
 setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);//設(shè)置不默認(rèn)關(guān)閉
 addWindowListener(new WindowListener() {
 
  @Override
  public void windowOpened(WindowEvent e) {
  // TODO Auto-generated method stub
 
  }
 
  @Override
  public void windowIconified(WindowEvent e) {
  // TODO Auto-generated method stub
 
  }
 
  @Override
  public void windowDeiconified(WindowEvent e) {
  // TODO Auto-generated method stub
 
  }
 
  @Override
  public void windowDeactivated(WindowEvent e) {
  // TODO Auto-generated method stub
 
  }
 
  @Override
  public void windowClosing(WindowEvent e) {
  // TODO Auto-generated method stub
  int x = JOptionPane.showConfirmDialog(null, "確認(rèn)退出么?", "友情提示", JOptionPane.OK_CANCEL_OPTION,
   JOptionPane.WARNING_MESSAGE);
  if (x == 0) {
   System.exit(0);
  }
  }
 
  @Override
  public void windowClosed(WindowEvent e) {
  // TODO Auto-generated method stub
  }
 
  @Override
  public void windowActivated(WindowEvent e) {
  // TODO Auto-generated method stub
 
  }
 });
 }
}

二、創(chuàng)建ClockText類(lèi)用于測(cè)試

public class ClockText{
 public static void main(String[] args) {
 new Clock();
 }
}

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

相關(guān)文章

  • 使用javaMail實(shí)現(xiàn)發(fā)送郵件

    使用javaMail實(shí)現(xiàn)發(fā)送郵件

    這篇文章主要為大家詳細(xì)介紹了使用javaMail實(shí)現(xiàn)發(fā)送郵件,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-08-08
  • PowerJob的HashedWheelTimer工作流程源碼解讀

    PowerJob的HashedWheelTimer工作流程源碼解讀

    這篇文章主要為大家介紹了PowerJob的HashedWheelTimer工作流程源碼解讀,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2024-01-01
  • Java Character類(lèi)對(duì)單個(gè)字符操作原理解析

    Java Character類(lèi)對(duì)單個(gè)字符操作原理解析

    這篇文章主要介紹了Java Character類(lèi)對(duì)單個(gè)字符操作原理解析,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-03-03
  • Java創(chuàng)建型設(shè)計(jì)模式之單例模式

    Java創(chuàng)建型設(shè)計(jì)模式之單例模式

    Java單例模式是一種設(shè)計(jì)模式,它確保一個(gè)類(lèi)只有一個(gè)實(shí)例,并提供一個(gè)全局訪(fǎng)問(wèn)點(diǎn)??梢允褂枚喾N方式實(shí)現(xiàn)單例模式,如餓漢式、懶漢式、雙重檢查鎖定、靜態(tài)內(nèi)部類(lèi)、枚舉等,每種方式都有其優(yōu)缺點(diǎn),需要根據(jù)具體情況選擇使用
    2023-05-05
  • @ComponentScan注解用法之包路徑占位符解析

    @ComponentScan注解用法之包路徑占位符解析

    這篇文章主要介紹了@ComponentScan注解用法之包路徑占位符解析,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2021-08-08
  • 基于SpringBoot解決CORS跨域的問(wèn)題(@CrossOrigin)

    基于SpringBoot解決CORS跨域的問(wèn)題(@CrossOrigin)

    這篇文章主要介紹了基于SpringBoot解決CORS跨域的問(wèn)題(@CrossOrigin),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2021-01-01
  • Spring session整合到Redis過(guò)程解析

    Spring session整合到Redis過(guò)程解析

    這篇文章主要介紹了Spring session整合到Redis過(guò)程解析,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2019-11-11
  • Spring單元測(cè)試類(lèi)ApplicationTests錯(cuò)誤的解決

    Spring單元測(cè)試類(lèi)ApplicationTests錯(cuò)誤的解決

    這篇文章主要介紹了Spring單元測(cè)試類(lèi)ApplicationTests錯(cuò)誤的解決,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-01-01
  • Java中多態(tài)的實(shí)現(xiàn)原理詳細(xì)解析

    Java中多態(tài)的實(shí)現(xiàn)原理詳細(xì)解析

    這篇文章主要介紹了Java中多態(tài)的實(shí)現(xiàn)原理詳細(xì)解析,多態(tài)是面向?qū)ο缶幊陶Z(yǔ)言的重要特性,它允許基類(lèi)的指針或引用指向派生類(lèi)的對(duì)象,而在具體訪(fǎng)問(wèn)時(shí)實(shí)現(xiàn)方法的動(dòng)態(tài)綁定,需要的朋友可以參考下
    2024-01-01
  • Java時(shí)間輪算法的實(shí)現(xiàn)代碼示例

    Java時(shí)間輪算法的實(shí)現(xiàn)代碼示例

    本篇文章主要介紹了Java時(shí)間輪算法的實(shí)現(xiàn)代碼示例,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-08-08

最新評(píng)論