Java線程實現時間動態顯示
本文實例為大家分享了Java線程實現時間動態顯示的具體代碼,供大家參考,具體內容如下
代碼如下:
import javax.swing.*;import java.awt.*;import java.util.Date;public class Test1 { public static void main(String[] args) {JFrame frame = new JFrame('我的窗口');frame.setBounds(200,200,400,400);JTextField textField=new JTextField();frame.add(textField);new Thread(new Runnable() { @Override public void run() {while(true){ try {Thread.sleep(1000); } catch (InterruptedException e) {e.printStackTrace(); } Date date=new Date(); textField.setText(date.getHours()+':'+date.getMinutes()+':'+date.getSeconds()); textField.setFont(new Font('楷體',Font.BOLD,20));} }}).start();frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);frame.setVisible(true); }}
運行結果:
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網。
相關文章:
1. Python獲取抖音關注列表封號賬號的實現代碼2. ajax請求添加自定義header參數代碼3. Python數據分析之pandas函數詳解4. 解決Python 進程池Pool中一些坑5. php測試程序運行速度和頁面執行速度的代碼6. 無線標記語言(WML)基礎之WMLScript 基礎第1/2頁7. 三個不常見的 HTML5 實用新特性簡介8. 使用.net core 自帶DI框架實現延遲加載功能9. php網絡安全中命令執行漏洞的產生及本質探究10. Warning: require(): open_basedir restriction in effect,目錄配置open_basedir報錯問題分析
