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 getComputedStyle2. 詳解瀏覽器的緩存機(jī)制3. .NET SkiaSharp 生成二維碼驗(yàn)證碼及指定區(qū)域截取方法實(shí)現(xiàn)4. jsp EL表達(dá)式詳解5. jsp實(shí)現(xiàn)登錄驗(yàn)證的過(guò)濾器6. css代碼優(yōu)化的12個(gè)技巧7. msxml3.dll 錯(cuò)誤 800c0019 系統(tǒng)錯(cuò)誤:-2146697191解決方法8. jsp+servlet簡(jiǎn)單實(shí)現(xiàn)上傳文件功能(保存目錄改進(jìn))9. 爬取今日頭條Ajax請(qǐng)求10. jsp cookie+session實(shí)現(xiàn)簡(jiǎn)易自動(dòng)登錄
