Search code examples
javaswingjnlpjava-web-start

Using SwingEventMonitor to monitor other applications?


How do I use SwingEventMonitor to monitor mouse events in applications running in other JVMs?

The demo code I have can monitor mouse clicks in applications running within its own JVM, but applications started seperately or via jnlp are ignored.

How do I make sure Java loads my SwingEventMonitor app with every application, regardless of how its started (desktop or jnlp)


Solution

  • Run your monitor and create a sever = ServerSocket(MONITOR_PORT). Then listen for incoming connections:

    while (true) {
        Socket socket = server.accept();
        connectionCount++;
        // start a new monitor thread for this connection
    }
    

    Note: SwingEventMonitor is not included anymore in JDK1.7, you may wish to push your own EventQueue. See What happened to SwingEventMonitor?