亚洲激情专区-91九色丨porny丨老师-久久久久久久女国产乱让韩-国产精品午夜小视频观看

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

Java中怎么實現動態數字時鐘

發布時間:2021-08-07 11:56:53 來源:億速云 閱讀:119 作者:Leah 欄目:編程語言

Java中怎么實現動態數字時鐘,相信很多沒有經驗的人對此束手無策,為此本文總結了問題出現的原因和解決方法,通過這篇文章希望你能解決這個問題。

一、Clock類

四個JPnal 三個放時間 最后一個放日期  放時間的三個JPnal 分別加入 地點 時間 按鈕  最后一個按鈕添加日期

具體實現如下:

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)); }  // 關系 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("北京時間"); jLabelBeijing.setFont(placeFont); jPanelBeijing.add(jLabelBeijing); setWestPanel(); JLabel jLabelNewYork = new JLabel("紐約時間"); jLabelNewYork.setFont(placeFont); jPanelNewYork.add(jLabelNewYork); setCenterPanel(); JLabel jLabelLondon = new JLabel("倫敦時間"); 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();  // 轉換日期顯示格式  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("北京繼續");   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();  // 轉換日期顯示格式  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("紐約繼續");   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(" 當前日期: " + 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("倫敦繼續");   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(" 當前日期: " + date.format(new Date(timemillis)));  } }); timeAction.start(); jPanelDate.add(jLabelDate); }  private void jFrameClick(){ setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);//設置不默認關閉 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, "確認退出么?", "友情提示", 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   } }); }}

二、創建ClockText類用于測試

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

看完上述內容,你們掌握Java中怎么實現動態數字時鐘的方法了嗎?如果還想學到更多技能或想了解更多相關內容,歡迎關注億速云行業資訊頻道,感謝各位的閱讀!

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

尚义县| 南安市| 新乡县| 永济市| 昌黎县| 申扎县| 白山市| 会泽县| 崇明县| 韶山市| 观塘区| 虹口区| 广水市| 雅安市| 惠水县| 阜城县| 姜堰市| 涟水县| 仙桃市| 宝丰县| 卢氏县| 吴江市| 双辽市| 武安市| 通海县| 双牌县| 洪洞县| 海原县| 高青县| 巴彦县| 玛多县| 镇平县| 疏附县| 宝丰县| 西昌市| 郧西县| 双辽市| 镇康县| 屯留县| 明水县| 新田县|