首页 > 编程语言 > 详细

实验十四:线程设计

时间:2019-06-30 18:06:25      阅读:98      评论:0      收藏:0      [点我收藏+]

源代码:

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

 

 

运行结果:

技术分享图片

 

实验十四:线程设计

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!