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("执行任务");
}
}