javafx-定时弹出窗口形式的弹窗

40 篇文章 0 订阅
  /**
     * 2023年2月1日14:12:13
     * 每日打开提示
     */
    public void clockinMessage(){

        TimerTask clockinTask0830 = new TimerTask() {
            @Override
            public void run() {
                Platform.runLater(new Runnable() {
                    @Override
                    public void run() {
                        showWindowAlert("大哥看下手机打卡了,早上8点30了,不看就要走流程了");
                    }
                });

            }
        };

        TimerTask clockinTask1800 = new TimerTask() {
            @Override
            public void run() {
                Platform.runLater(new Runnable() {
                    @Override
                    public void run() {
                        showWindowAlert("大哥看下手机打卡了,下午18点打卡了,不看就要走流程了");
                    }
                });
            }
        };

        TimerTask clockinTask2030 = new TimerTask() {
            @Override
            public void run() {
                Platform.runLater(new Runnable() {
                    @Override
                    public void run() {
                        showWindowAlert("大哥看下手机打卡了,晚上20点30分打卡了,不看就要走流程了");
                    }
                });
            }
        };

        //设置执行时间
        Calendar calendar = Calendar.getInstance();
        int year = calendar.get(Calendar.YEAR);
        int month = calendar.get(Calendar.MONTH);
        int day = calendar.get(Calendar.DAY_OF_MONTH);//每天

        //定制每天的08:30:00执行,
        calendar.set(year, month, day, 8, 27, 00);
        Date date = calendar.getTime();

        //创建定时器
        Timer clockinTimer = new Timer();
        //设置的定时器 period(每隔多长时间运行几次) 单位毫秒
        clockinTimer.schedule(clockinTask0830, date);

        //定制每天的18:00:00执行,
        calendar.set(year, month, day, 17, 57, 00);
        Date date1800 = calendar.getTime();
        clockinTimer.schedule(clockinTask1800, date1800);

        //20:30:00执行,
        calendar.set(year, month, day, 20, 27, 00);
        Date date2030 = calendar.getTime();
        clockinTimer.schedule(clockinTask2030, date2030);
        logger.info("start clockin message");
    }

    /**
     * 2023-2-1 14:11:42
     * 窗口形式对话框
     * @param message
     */
    void showWindowAlert(String message){
        Stage stage = new Stage();
        stage.setTitle("每日打开提示");

        DialogPane dialogPane = new DialogPane();
        dialogPane.setPadding(new Insets(5,5,5,5));
        ImageView imageView = new ImageView("/talk.png");
        imageView.setFitWidth(50);
        imageView.setPreserveRatio(true);
        dialogPane.setGraphic(imageView);

        dialogPane.setContentText(message);

        stage.initModality(Modality.WINDOW_MODAL);
        stage.setResizable(false);
        stage.setFullScreen(true);
        stage.setAlwaysOnTop(true);
        stage.setScene(new Scene(dialogPane));
        stage.show();
    }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值