import java.lang.reflect.*;
import java.applet.*;

/*
 *    Processing has strange problems with the term "Method" ..
 *
 */

public class Callback
{
    public static void callback ( Applet applet)
    {
        System.err.println( "callback() - starting ..." );
        try { 
            Class c = Class.forName("netscape.javascript.JSObject");

            Method getWin = c.getMethod( "getWindow", new Class[]{ Applet.class } );

            Method eval = c.getMethod( "eval", new Class[]{ String.class } ); 

            Object jswin = getWin.invoke( c, new Object[]{ applet } );

            if ( jswin != null )
                eval.invoke(jswin, new Object[]{ "alert(\'(via JSObject) Processing says hello!\')" } );
            
            System.err.println( "callback() - done. (after JSObject)" );
            return;
        } catch (Exception e) { ; }

        try {
            AppletContext context = applet.getAppletContext();
            if ( context != null ) {
                context.showDocument( new java.net.URL("javascript:" + "(via showDocument) alert(\'Processing says hello!\')"), "_self" );
            }
        } catch (Exception e) { ; }

        System.err.println( "callback() - done. (after showDocument)" );
    }
}

