• 下班定时


    package com.freeter.Timingtask;

    import javax.swing.*;
    import java.awt.*;
    import java.util.*;
    import java.util.Timer;

    /**
    * author LIUQI
    **/
    //定时任务
    public class TimingTask {
    public static Timer timer;
    public static Scanner scanner = new Scanner(System.in);
    public static int hour = scanner.nextInt();
    public static int minute = scanner.nextInt();
    public static int second = scanner.nextInt();


    public TimingTask() {


    Date time = getDate();
    timer = new Timer();
    timer.schedule(new TimerWorking(), time);
    }

    //封装日期类
    public Date getDate() {
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.HOUR_OF_DAY, hour);//时
    calendar.set(Calendar.MINUTE, minute);//分
    calendar.set(Calendar.SECOND, second);//秒
    Date time = calendar.getTime();//获取时间

    return time;//返回时间类型
    }


    public class TimerWorking extends TimerTask {
    public void run() {

    System.out.println("任务已执行!!!!!!!");
    JFrame frame = new JFrame("闹钟提醒");
    JLabel label = new JLabel();
    label.setText("下班啦 下班啦 一天结束啦");
    frame.setBounds(200,400,600,400);
    frame.add(label);
    frame.setVisible(true);


    }
    }

    public static void main(String[] args) {

    System.out.println("请输入执行的小时:" + TimingTask.hour);

    System.out.println("请输入执行的分钟:" +TimingTask.minute);
    System.out.println("请输入执行的秒数:" + TimingTask.second);
    new TimingTask(); //初始化TimingTask类
    System.out.println("执行任务");

    }

    }
  • 相关阅读:
    Sqlserver 获得范围内的随机数过程
    Alpha项目测试
    第三次作业
    第二次作业
    Surprise团队项目总结
    Surprise团队第四周项目总结
    Surprise团队第三周项目总结
    Surprise团队第二周项目总结
    Surprise团队第一周项目总结
    5种常用的相关分析方法
  • 原文地址:https://www.cnblogs.com/LQ970811/p/12188556.html
Copyright © 2020-2023  润新知