实验十四:线程设计

实验代码:

package 实验14;
 
import java.awt.FlowLayout;
import java.awt.Font;
 
import javax.swing.JFrame;
import javax.swing.JLabel;
class TIME extends JFrame{
     
    int day =365;
    int seconds=day*24*60*60;
    private JLabel text;
    public void run() {      
    while (seconds > 0) {
        seconds--;
        int days=seconds/60/60/24;
        int hours= seconds/60/60%24;
        int minutes= seconds/60%60;
        int second=seconds%60;
       System.out.println(days+"天"+hours+"时"+minutes+"分"+second+"秒");     
       try {
            this.text.setText(days+"天"+hours+"时"+minutes+"分"+second+"秒");
            Thread.sleep(1000);
                }
       catch (InterruptedException e) {
                    e.printStackTrace();
                }      
          }}
        public TIME(){
        this.setLayout(new FlowLayout());  
        this.setTitle("Introduction");
        this.setSize(320,200);
        this.setLocation(300,240);
        this.add(new JLabel("距离毕业还剩")).setFont(new Font("黑体", 1, 20));    
        this.text=new JLabel("365天00时00分00秒");
        this.add(text).setFont(new Font("黑体", 1, 30));
         
        this.setVisible(true);}
      }
     
 
public class Shiyan14 {
     
    public static void main(String[] args)
    {
            new TIME().run();    
            }
}

实验结果:

 

posted @ 2019-06-30 20:36  EvilTime  阅读(116)  评论(0编辑  收藏  举报