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. 以PHP代碼為實(shí)例詳解RabbitMQ消息隊(duì)列中間件的6種模式2. html小技巧之td,div標(biāo)簽里內(nèi)容不換行3. laravel ajax curd 搜索登錄判斷功能的實(shí)現(xiàn)4. python實(shí)現(xiàn)自動(dòng)化辦公郵件合并功能5. python web框架的總結(jié)6. Python基礎(chǔ)之numpy庫(kù)的使用7. nestjs實(shí)現(xiàn)圖形校驗(yàn)和單點(diǎn)登錄的示例代碼8. Python 如何將integer轉(zhuǎn)化為羅馬數(shù)(3999以內(nèi))9. Echarts通過(guò)dataset數(shù)據(jù)集實(shí)現(xiàn)創(chuàng)建單軸散點(diǎn)圖10. css進(jìn)階學(xué)習(xí) 選擇符
