十四线程设计
Posted dyl1923
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了十四线程设计相关的知识,希望对你有一定的参考价值。
1.程序代码
package shiyan14;
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);
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);
2.结果
3.心得
要认真看书学习线程知识,认真理解,充分利用。
以上是关于十四线程设计的主要内容,如果未能解决你的问题,请参考以下文章