其他分享
首页 > 其他分享> > 实验十四:线程设计

实验十四:线程设计

作者:互联网

源代码:

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();
}
}

 

 

运行结果:

 

标签:import,time,FlowLayout,实验,jLabel,new,线程,十四,public
来源: https://www.cnblogs.com/LHT-548/p/11110576.html