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();
        }
    }
  • 相关阅读:
    vue项目根据不同环境动态配置接口
    微信内置浏览器手机按返回键,给出提示,是否要退出
    Mac更新系统后提示xcrun error
    curl请求本地域名问题
    PHP把PNG图片转化为JPG时透明背景变黑色
    安卓微信浏览器中window.location.href失效的问题
    上拉加载触底事件最简单写法
    记一次virtualbox和夜神模拟器冲突的问题
    技术总结
    input type file onchange上传文件的过程中,同一个文件二次上传无效的问题。
  • 原文地址:https://www.cnblogs.com/a709898670/p/9455607.html
Copyright © 2011-2022 走看看