实验十四:线程设计

2020-12-13 04:27

阅读:476

标签:http   转化   class   exce   tle   cti   trace   vax   rac   

源代码:

package 多线程;

import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;

public class XianCheng extends JFrame{
JButton jButton;
JLabel jLabel;
int time=8640000;//一百天转化为秒
public XianCheng() {
FlowLayout fl=new FlowLayout(FlowLayout.CENTER);
this.setLayout(fl);
jButton=new JButton("倒数一百天(8640000秒)");
//时间倒计时
jLabel=new JLabel();
new Thread(){
public void run() {
while(time>0) {
time--;
jLabel.setText(time+"秒");
try {
Thread.sleep(1000);
}
catch (InterruptedException e) {
e.printStackTrace();
}
}}
}.start();

this.add(jButton);
this.add(jLabel);
this.setTitle("倒计时一百天");
this.setBounds(700, 500, 360, 110);
this.setResizable(true);
this.setVisible(true);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public static void main(String[] args) {
new XianCheng();
}
}

 

 

运行结果:

技术图片

 

实验十四:线程设计

标签:http   转化   class   exce   tle   cti   trace   vax   rac   

原文地址:https://www.cnblogs.com/LHT-548/p/11110576.html


评论


亲,登录后才可以留言!