public static void setHandler(OSXAdapter adapter) {
        try {
            Class<?> applicationClass = Class.forName("com.apple.eawt.Application");
            if (macOSXApplication == null) {
                macOSXApplication = applicationClass.getConstructor((Class[])null).newInstance((Object[])null);
            }
            Class<?> applicationListenerClass = Class.forName("com.apple.eawt.ApplicationListener");
            Method addListenerMethod = applicationClass.getDeclaredMethod("addApplicationListener", new Class[] { applicationListenerClass });
            // Create a proxy object around this handler that can be reflectively added as an Apple ApplicationListener
            Object osxAdapterProxy = Proxy.newProxyInstance(OSXAdapter.class.getClassLoader(), new Class[] { applicationListenerClass }, adapter);
            addListenerMethod.invoke(macOSXApplication, new Object[] { osxAdapterProxy });
        } catch (ClassNotFoundException cnfe) {
            System.err.println("This version of Mac OS X does not support the Apple EAWT.  ApplicationEvent handling has been disabled (" + cnfe + ")");
        } catch (Exception ex) {  // Likely a NoSuchMethodException or an IllegalAccessException loading/invoking eawt.Application methods
            System.err.println("Mac OS X Adapter could not talk to EAWT:");
            ex.printStackTrace();
        }
    }
public static void setHandler ( OSXAdapter adapter ) { try { Class < ? > applicationClass = Class . forName ( "com.apple.eawt.Application" ) ; if ( macOSXApplication == null ) { macOSXApplication = applicationClass . getConstructor ( ( Class [ ] ) null ) . newInstance ( ( Object [ ] ) null ) ; } Class < ? > applicationListenerClass = Class . forName ( "com.apple.eawt.ApplicationListener" ) ; Method addListenerMethod = applicationClass . getDeclaredMethod ( "addApplicationListener" , new Class [ ] { applicationListenerClass } ) ; Object osxAdapterProxy = Proxy . newProxyInstance ( OSXAdapter . class . getClassLoader ( ) , new Class [ ] { applicationListenerClass } , adapter ) ; addListenerMethod . invoke ( macOSXApplication , new Object [ ] { osxAdapterProxy } ) ; } catch ( ClassNotFoundException cnfe ) { System . err . println ( "This version of Mac OS X does not support the Apple EAWT.  ApplicationEvent handling has been disabled (" + cnfe + ")" ) ; } catch ( Exception ex ) { System . err . println ( "Mac OS X Adapter could not talk to EAWT:" ) ; ex . printStackTrace ( ) ; } }
setHandler creates a Proxy object from the passed OSXAdapter and adds it as an ApplicationListener