简体   繁体   English

有没有办法使用 Java 向 Windows 通知区域添加“按钮”

[英]Is there any way to add a "button" to the Windows Notification Area using Java

I have made a small workout reminder app that reminds me at the top of every hour to do some workouts -- Is there any way to add some buttons to this saying "I did it" / "I skipped it?"我做了一个小的锻炼提醒应用程序,它会在每小时结束时提醒我做一些锻炼——有什么方法可以添加一些按钮来表达“我做到了”/“我跳过了它?” or something?或者其他的东西? Source code below, but probably not relevant to the question at hand:下面的源代码,但可能与手头的问题无关:

在此处输入图像描述

import java.awt.*;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Random;

public class WorkoutReminder {
    static final String workouts[] = {
    "Pushups", "Curls", "Squats", "Crunches", "Lat raise", "Kneeling hammer Press",             "Reverse pushups",
     "Ab roller"
};
    static final int reps[] = {
            10,14,15,17,20
    };
    public static void main(String args[])throws AWTException, InterruptedException{
        if(SystemTray.isSupported()) {
            WorkoutReminder wr = new WorkoutReminder();
            wr.displayReminder();
        }
        else{
            System.out.println("Run this on windows plz <3");
        }
    }

    private static void displayReminder() throws AWTException, InterruptedException{
        while (true) {
            DateTimeFormatter dtfm = DateTimeFormatter.ofPattern("mm");
            DateTimeFormatter dtfh = DateTimeFormatter.ofPattern("HH");
            LocalDateTime currentTime = LocalDateTime.now();
            String min = dtfm.format(currentTime);
            int hour = Integer.parseInt(dtfh.format(currentTime));
            System.out.print(min);
            if(min.equals("00") && ( hour >=9 && hour <= 21)) {
                Random rand = new Random();
                String workout = workouts[Math.abs(rand.nextInt() % workouts.length)];
                int rep = reps[Math.abs(rand.nextInt() % reps.length)];

                SystemTray st = SystemTray.getSystemTray();
                Image logo = Toolkit.getDefaultToolkit().createImage("image.png");
                TrayIcon trayIcon = new TrayIcon(logo, "Workout you fat slob");
                trayIcon.setImageAutoSize(true);
                String iconText = "Workout reminder";
                String workoutText = "Let's get it: " + workout + " for " + rep + " reps\n";
                System.out.print("  --" + workoutText);
                trayIcon.setToolTip("YEEEET");
                st.add(trayIcon);
                trayIcon.displayMessage(workoutText, iconText, TrayIcon.MessageType.INFO);
                Thread.sleep(60000);
            }
            else{
                System.out.print(" - " + (60-Integer.parseInt(min)) + " minutes left\n");
                Thread.sleep(60000);
            }
        }
    }
}

I don't know if you can do this in Java directly (maybe you can, I just don't know), but what you could do is call a powershell script from java that can do this.我不知道你是否可以直接在 Java 中执行此操作(也许你可以,我只是不知道),但你可以做的是从 java 调用一个 powershell 脚本来执行此操作。

For more info on creating these scripts: https://eddiejackson.net/wp/?p=18877有关创建这些脚本的更多信息: https://eddiejackson.net/wp/?p=18877

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Java中的Windows的通知区域中更改图标名称 - Change the icon name in the notification area in windows in Java 有没有办法使用javafx向画布添加按钮 - Is there any way to add a button to a canvas using javafx 有什么方法可以使用Java在Windows中以编程方式触发全局MediaKey? - Any way to programatically trigger global mediakeys in Windows using Java? 使用java发送Windows Phone 7的推送通知 - send push notification for windows phone 7 using java 除了双击按钮之外,还有其他方法可以在设计模式下使用 windowbuilder(eclipse)将 ActionListener 添加到按钮吗? - Is there any other way to add an ActionListener to a button using windowbuilder (eclipse) in design mode than to double click on the button? 有没有办法使用Java的Windows 7多点触控? - Is there any way to use Windows 7 multitouch from Java? 有没有办法在不使用任何解析器的情况下在 java 的特定位置添加另一个包含所有详细信息的标签 - Is there any way to add another tag with all the details at specific place in java without using any parser 有什么方法可以在Java中使用SenseRelate? - Is there any way of using SenseRelate in Java? 有什么办法可以访问http:// <someserver.com> : <portnumber> Windows中使用Java代码的/logs.log.txt - Is there any way to access http://<someserver.com>:<portnumber>/logs.log.txt using Java code in windows 向通知添加按钮 - Add Button to Notification
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM