首页 > 其他 > 详细

实验十四

时间:2019-06-30 19:41:31      阅读:113      评论:0      收藏:0      [点我收藏+]
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class SwitchTest {

private JFrame jFrame;
private JLabel jl1;
private JLabel jl2;
private JLabel jl3;

public static void main(String[] args) {
new SwitchTest().getTime();
}

private void getTime() {
long time = 3600;
long hour = 0;
long minute = 0;
long seconds = 0;
while (time > 0) {
hour = time / 3600;
minute = (time - hour * 3600) / 60;
seconds = time - hour * 3600 - minute * 60;
jl1.setText(hour + "时");
jl2.setText(minute + "分");
jl3.setText(seconds + "秒");
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
time--;
}
}
public SwitchTest() {
jFrame = new JFrame("倒计时");
jl1 = new JLabel();
jl2 = new JLabel();
jl3 = new JLabel();
init();
}
private void init() {
JPanel jPanel = new JPanel();
jPanel.add(jl1);
jPanel.add(jl2);
jPanel.add(jl3);
jFrame.add(jPanel);
jFrame.setVisible(true);
jFrame.setLocation(300, 400);
jFrame.setSize(300, 200);
jFrame.setDefaultCloseOperation(jFrame.EXIT_ON_CLOSE);
}
}
实验心得:对我而言,本次实验有很大的难度,但是通过借鉴网上资料和别人的帮助艰难的完成了本次实验。

实验十四

原文:https://www.cnblogs.com/yanqianying1/p/11110844.html

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