gpt4 book ai didi

java - 有没有办法使用Java将 "button"添加到Windows通知区域

转载 作者:行者123 更新时间:2023-12-03 11:05:23 26 4
gpt4 key购买 nike

我制作了一个小的锻炼提醒应用程序,它会在每小时开始时提醒我做一些锻炼——有没有办法在上面添加一些按钮说“我做到了”/“我跳过了”?或者其他的东西?下面的源代码,但可能与手头的问题无关:
enter image description here

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);
}
}
}
}

最佳答案

我不知道您是否可以直接在 Java 中执行此操作(也许可以,我只是不知道),但是您可以做的是从可以执行此操作的 Java 中调用 powershell 脚本。
有关创建这些脚本的更多信息:https://eddiejackson.net/wp/?p=18877

关于java - 有没有办法使用Java将 "button"添加到Windows通知区域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63220735/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com