Java線程實(shí)現(xiàn)時(shí)間動(dòng)態(tài)顯示
本文實(shí)例為大家分享了Java線程實(shí)現(xiàn)時(shí)間動(dòng)態(tài)顯示的具體代碼,供大家參考,具體內(nèi)容如下
代碼如下:
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); }}
運(yùn)行結(jié)果:

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. 如何用JS實(shí)現(xiàn)簡(jiǎn)單的數(shù)據(jù)監(jiān)聽2. 使用Docker的NFS-Ganesha鏡像搭建nfs服務(wù)器的詳細(xì)過程3. 詳解PHP laravel中的加密與解密函數(shù)4. 詳解SpringBoot中關(guān)于%2e的Trick5. Docker容器如何更新打包并上傳到阿里云6. idea修改背景顏色樣式的方法7. golang json數(shù)組拼接的實(shí)例8. docker容器調(diào)用yum報(bào)錯(cuò)的解決辦法9. 利用CSS制作3D動(dòng)畫10. Python使用Excel將數(shù)據(jù)寫入多個(gè)sheet

網(wǎng)公網(wǎng)安備