// Notification in Windows OS using JAVA AWT //

import java.awt.*;
import java.awt.event.*;
import java.awt.TrayIcon.MessageType;
import java.net.MalformedURLException;
public class Notification {
    public static void main(String[] args) {Notification app = new Notification();}
    public Notification(){
        Frame f = new Frame();
        Button btn = new Button("Click Here");
        btn.setBounds(150,150,80,30);
        f.add(btn);
        f.setSize(400,400);
        f.setLayout(null);
        f.setVisible(true);
        f.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                f.dispose();
            }
        });

        Notification _this = this;
        btn.addActionListener(new ActionListener()
        {
            @Override
            public void actionPerformed(ActionEvent e)
            {
                if (SystemTray.isSupported()) {
                    try{
                        _this.displayTray();
                    }catch(AWTException ex){

                    }catch(MalformedURLException ex){

                    }
                } else {
                    System.err.println("System tray not supported!");
                }
            }
        });
    }

    public void displayTray() throws AWTException, MalformedURLException {
        //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, "Java AWT 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", "Java Notification Demo In Windows", MessageType.INFO);
    }
}