zoukankan      html  css  js  c++  java
  • 实验十四:线程设计

    实验代码:

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

    实验结果:

    实验心得:本次实验还是较难的,希望继续努力吧

  • 相关阅读:
    HBase写请求分析
    jquery+easyui主界面布局一例
    调试LD_PRELOAD注入的代码
    获取Oracle隐含參数信息
    Android组件系列----ContentProvider内容提供者【4】
    053第401题
    高速排序优化通过中位数优化
    较难理解的概念
    HDU 2546 饭卡(dp)
    HDU 2546 饭卡(dp)
  • 原文地址:https://www.cnblogs.com/Java199-wfx/p/11110548.html
Copyright © 2011-2022 走看看