Java線程實(shí)現(xiàn)時(shí)間動態(tài)顯示
本文實(shí)例為大家分享了Java線程實(shí)現(xiàn)時(shí)間動態(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é)果:
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. 得到XML文檔大小的方法2. WMLScript的語法基礎(chǔ)3. 使用Spry輕松將XML數(shù)據(jù)顯示到HTML頁的方法4. ASP中if語句、select 、while循環(huán)的使用方法5. xml中的空格之完全解說6. ASP中解決“對象關(guān)閉時(shí),不允許操作。”的詭異問題……7. 輕松學(xué)習(xí)XML教程8. html小技巧之td,div標(biāo)簽里內(nèi)容不換行9. XML入門的常見問題(四)10. msxml3.dll 錯(cuò)誤 800c0019 系統(tǒng)錯(cuò)誤:-2146697191解決方法
