到底有多少个小谢 2020-03-16 16:10 采纳率: 0%
浏览 676
已采纳

请问有人知道如何用java向win10的通知栏推送消息吗?

我在自己的电脑上用tomcat部署了一套java web 系统,我希望系统里面有提醒或待办的时候能够在没有启动浏览器的情况下,java后端直接定时向win10的通知栏推送消息。

  • 写回答

1条回答 默认 最新

  • threenewbee 2020-03-16 18:39
    关注

    https://stackoverflow.com/questions/34490218/how-to-make-a-windows-notification-in-java

    import java.awt.*;
    import java.awt.TrayIcon.MessageType;
    
    public class TrayIconDemo {
    
        public static void main(String[] args) throws AWTException {
            if (SystemTray.isSupported()) {
                TrayIconDemo td = new TrayIconDemo();
                td.displayTray();
            } else {
                System.err.println("System tray not supported!");
            }
        }
    
        public void displayTray() throws AWTException {
            //Obtain only one instance of the SystemTray object
            SystemTray tray = SystemTray.getSystemTray();
    
            //If the icon is a file
            Image image = Toolkit.getDefaultToolkit().createImage("icon.png");
            //Alternative (if the icon is on the classpath):
            //Image image = Toolkit.getDefaultToolkit().createImage(getClass().getResource("icon.png"));
    
            TrayIcon trayIcon = new TrayIcon(image, "Tray Demo");
            //Let the system resize the image if needed
            trayIcon.setImageAutoSize(true);
            //Set tooltip text for the tray icon
            trayIcon.setToolTip("System tray icon demo");
            tray.add(trayIcon);
    
            trayIcon.displayMessage("Hello, World", "notification demo", MessageType.INFO);
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料