zoukankan      html  css  js  c++  java
  • swing时钟

    import java.awt.*;
    import java.util.*;
    import javax.swing.*;
    public class HyClock extends JFrame implements Runnable {
        public static JLabel tm;
        public void run() {
            while (true) {
                Calendar c = Calendar.getInstance();
                String nowtime = c.get(Calendar.HOUR_OF_DAY) + ":" + c.get(Calendar.MINUTE) + ":" + c.get(Calendar.SECOND);
                tm.setText(nowtime);
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                }
            }
        }
     
        public static void main(String[] agrs) {
            HyClock  hytime = new HyClock();
            hytime.setLayout(new FlowLayout());
            tm = new JLabel();
            tm.setFont(new Font("宋体", 1, 40));
            tm.setForeground(Color.RED);
            hytime.add(tm);
            hytime.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
            hytime.setSize(300, 100);
            hytime.setVisible(true);
            hytime.setLocation(400, 400);
            Thread t = new Thread(hytime);
            t.start();
        }
    }
    import java.awt.*;
    import java.util.*;
    import javax.swing.*;
    public class HyClock extends JFrame implements Runnable {
        public static JLabel tm;
        public void run() {
            while (true) {
                Calendar c = Calendar.getInstance();
                String nowtime = c.get(Calendar.HOUR_OF_DAY) + ":" + c.get(Calendar.MINUTE) + ":" + c.get(Calendar.SECOND);
                tm.setText(nowtime);
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                }
            }
        }
     
        public static void main(String[] agrs) {
            HyClock  hytime = new HyClock();
            hytime.setLayout(new FlowLayout());
            tm = new JLabel();
            tm.setFont(new Font("宋体", 1, 40));
            tm.setForeground(Color.RED);
            hytime.add(tm);
            hytime.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
            hytime.setSize(300, 100);
            hytime.setVisible(true);
            hytime.setLocation(400, 400);
            Thread t = new Thread(hytime);
            t.start();
        }
    }
  • 相关阅读:
    Yarn安装与配置
    如何找到所有 HTML select 标签的选中项
    Jquery 获取某个样式除第一个以外的元素
    常用的字符串截取方法
    App的埋点测试
    手写 promise
    关于JSON.parse(JSON.stringify(obj))实现深拷贝应该注意的坑
    计算一个数组的深度
    数组的 交集 差集 补集 并集
    webpack -- element-ui 的按需引入
  • 原文地址:https://www.cnblogs.com/a709898670/p/9455607.html
Copyright © 2011-2022 走看看