Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Java Applet Embedding in Tiger



Eric Feigenson wrote:

>My application has Java byte code that it wants to run as an applet, so it
>just wants to open a window, and run the applet in that window. Sometime
>in the uncertain future, we might want to embed the applet in separate
>window (a window with other stuff in it), as opposed to it running in its
>own window, but that's not something I don't need to worry about right
>now.

If I understand your explanation correctly, you'll have exactly one applet
in each window, just as if you wrote a pure Java application that put each
Applet instance in a separate instance of a Frame or JFrame.

If that's all you want, then I think all you need is an implementation of
an AppletContext and AppletStub, along with an appropriate security
sub-system, so you can put the Applets into Frame or JFrame classes.  After
all, an Applet is a Component, and you can put Components in Frames using
calls from native code.  Then your application just calls into the JVM to a
known location that spawns one of these Frames, so at that point everything
is pretty much the straight JNI invocation API.

I once wrote some stub versions of AppletContext and AppletStub (below),
which were sufficient to place an Applet into a Frame.  It was dead simple,
so it omitted all the stuff like returning audio-clips and such that I knew
I didn't need.  Then the main() just made a Stub, a Frame, and an Applet,
and connected the pieces together.

Other than the main() and the System.exit() in the WindowListener, which
you'd want different in your app, it's a pretty straightforward pattern.
If my stripped-down stubs aren't enough to go on, you can probably take a
look at Sun's applet-runner Java code, or google for open-source
implementations like it.  If you can't find an applet runner, try looking
for an applet test-bed or an applet debugging environment.  The last time I
wanted something like this, I think that was where I found additional info.


I suspect a more difficult obstacle for you will that the 1.4 and 1.5 JVMs
are Cocoa-based, and have a Cocoa event-loop for AWT events.  As I recall,
this makes them unusable from within a Carbon app.  There was a past post
that asked about this:
  <http://lists.apple.com/archives/java-dev/2006/Jan/msg00054.html>

Or you can skip ahead to the answer:
  <http://lists.apple.com/archives/java-dev/2006/Jan/msg00063.html>

  -- GG


/* Freely released AS-IS into the public domain.  No warranty. */

  /** Show PlatformID applet in Frame. */
  public static void
  main( String[] args )
  {
    Frame frame = new Frame( "PlatformID" );

    Stub stub = new Stub();

    PlatformID applet = new PlatformID();
    applet.setStub( stub );

    frame.add( applet, BorderLayout.CENTER );
    frame.addWindowListener( stub );

    applet.init();

    frame.pack();
    frame.show();

    applet.start();
  }


/** Exits app at windowClosing(). */
public class Stub
  extends WindowAdapter
  implements AppletContext, AppletStub
{
  public void
  windowClosing( WindowEvent e )
  {  System.exit( 0 );  }


  // ## AppletStub

  /** Lie: always null. */
  public AudioClip getAudioClip( URL url )
  {  return ( null );  }

  /** Lie: always null. */
  public Image getImage( URL url )
  {  return ( null );  }

  /** Lie: always null. */
  public Applet getApplet( String name )
  {  return ( null );  }

  /** Lie: always null. */
  public Enumeration getApplets()
  {  return ( null );  }

  /** Lie: nothing. */
  public void showDocument( URL url )
  {  ;  }

  /** Lie: nothing. */
  public void showDocument( URL url, String target )
  {  ;  }

  /** Lie: nothing. */
  public void showStatus( String status )
  {  ;  }


  // ## AppletStub

  /** Lie: always active. */
  public boolean isActive()
  {  return ( true );  }

  /** Lie: null. */
  public URL getDocumentBase()
  {  return ( null );  }

  /** Lie: arbitrary URL. */
  public URL getCodeBase()
  {  return ( null );  }

  /** Lie: nothing. */
  public String getParameter( String name )
  {  return ( null );  }

  /** Lie: nothing. */
  public String xx( String name )
  {  return ( null );  }

  /** TRUTH: self. */
  public AppletContext getAppletContext()
  {  return ( this );  }

  /** Lie: nothing. */
  public void appletResize( int width, int height )
  {  ;  }
}


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Java-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/java-dev/email@hidden

This email sent to email@hidden



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.