0

Is it possible to listen to events from browser with Java?

The main task is to add command "copy to file" to pop-up menu of right click of the mouse. This command must add selected text in browser, in Notepad, in winword (any selectable text) to specific text file.

I've just tried code which adds icon to tray but I do not know whether it can it be developed for solving my task.

import java.awt.*;
import java.awt.event.*;
public class SystemTrayTest
{

    public SystemTrayTest()
    {

        final TrayIcon trayIcon;

        if (SystemTray.isSupported()) {

            SystemTray tray = SystemTray.getSystemTray();
            Image image = Toolkit.getDefaultToolkit().getImage("tray.gif");

            MouseListener mouseListener = new MouseListener() {

                public void mouseClicked(MouseEvent e) {
                    System.out.println("Tray Icon - Mouse clicked!");                 
                }
                public void mouseEntered(MouseEvent e) {
                    System.out.println("Tray Icon - Mouse entered!");                 
                }
                public void mouseExited(MouseEvent e) {
                    System.out.println("Tray Icon - Mouse exited!");                 
                }
                public void mousePressed(MouseEvent e) {
                    System.out.println("Tray Icon - Mouse pressed!");                 
                }
                public void mouseReleased(MouseEvent e) {
                    System.out.println("Tray Icon - Mouse released!");                 
                }

            };

            ActionListener exitListener = new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    System.out.println("Exiting...");
                    System.exit(0);
                }
            };

            PopupMenu popup = new PopupMenu();
            MenuItem defaultItem = new MenuItem("Exit");
            defaultItem.addActionListener(exitListener);
            popup.add(defaultItem);

            trayIcon = new TrayIcon(image, "Tray Demo", popup);

            ActionListener actionListener = new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    trayIcon.displayMessage("Action Event", 
                        "An Action Event Has Been Peformed!",
                        TrayIcon.MessageType.INFO);
                }
            };

            trayIcon.setImageAutoSize(true);
            trayIcon.addActionListener(actionListener);
            trayIcon.addMouseListener(mouseListener);

            //    Depending on which Mustang build you have, you may need to uncomment
            //    out the following code to check for an AWTException when you add 
            //    an image to the system tray.

            //    try {
                      tray.add(trayIcon);
            //    } catch (AWTException e) {
            //        System.err.println("TrayIcon could not be added.");
            //    }

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

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args)
    {
        SystemTrayTest main = new SystemTrayTest();
    }

}
pnuts
  • 58,317
  • 11
  • 87
  • 139
mirvel
  • 1

1 Answers1

0

You are talking about accessing clipboard events. this may helps you. How do we get notified about system clipboard events?

Community
  • 1
  • 1
shan
  • 1,164
  • 4
  • 14
  • 30