import java.awt.*;
import java.awt.event.*;

public class TrayIconExample {

    public static void main(String[] args) {
        // Create a new tray icon
        SystemTray tray = SystemTray.getSystemTray();
        Image image = Toolkit.getDefaultToolkit().getImage("path/to/your/icon.png"); // Replace with the path to your image
        PopupMenu popup = new PopupMenu();
        MenuItem exitItem = new MenuItem("Exit");
        popup.add(exitItem);

        TrayIcon trayIcon = new TrayIcon(image, "My Tray Icon", popup);
        try {
            tray.add(trayIcon);
        } catch (AWTException e) {
            System.out.println("Error: tray icon not supported");
            System.exit(1);
        }

        // Add a mouse listener
        trayIcon.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                if (e.getButton() == MouseEvent.BUTTON1) {
                    System.out.println("Left button clicked");
                } else if (e.getButton() == MouseEvent.BUTTON2) {
                    System.out.println("Middle button clicked");
                } else if (e.getButton() == MouseEvent.BUTTON3) {
                    System.out.println("Right button clicked");

                }
            }
        });

        // Add a listener for the exit event
        exitItem.addActionListener(e -> System.exit(0));

        // Main loop to keep the application running
        while (true) {
            try {
                Thread.sleep(1000); // Check every second
            } catch (InterruptedException ex) {
                // Handle the interruption
            }
        }
    }
} 