开发者

Embedding a JFrame in an Applet

开发者 https://www.devze.com 2023-03-31 13:40 出处:网络
I have found an open source application that creates a JFrame to display some content. I w开发者_C百科ould like to \"embed\" this JFrame into an applet, so everything that is displayed in the Jframe w

I have found an open source application that creates a JFrame to display some content. I w开发者_C百科ould like to "embed" this JFrame into an applet, so everything that is displayed in the Jframe will be displayed in the applet - is this possible?

Thanks for your help!


  1. Create an instance of the frame.
  2. Get the content pane of the frame.
  3. Add the content pane to the applet.


..open source application that creates a JFrame..

Since the source is available, take whatever they do in the frame, and do that instead in an applet (with some slight variants & gotchas).

Some typical problems with using the frame content in an applet are that:

  1. The programmers might have set the GUI visible in the constructor, meaning you cannot get access to the content pane without showing a free floating GUI element on-screen.
  2. Custom painting direct to the frame (eeek). There's no getting that stuff. But then, any programmer that incompetent should not be 'open'ing their source in the first place.
  3. A frame programmer would typically use EXIT_ON_CLOSE as an exit behavior for the frame. It is not permitted (or necessary) for a sand-boxed applet to end the VM. Even a trusted applet would (and should) normally be prevented from calling System.exit(int).
  4. Frame based code often does things that either require trust in an applet, or alternate strategies to achieve the same goal.

Points 3 & 4 are less applicable/relevant if the frame was designed to be launched using web start. And since I mention webstart..

Note that it is generally easier to 'convert' a frame to be launched using Java Web Start than it is either to create and deploy an applet, or to convert a frame to an applet. Unless there is some functionality of an applet that is vital & not available to an application (which is unlikely, given you started with the application), I would recommend launching the app. via JWS, rather than doing a conversion.

0

精彩评论

暂无评论...
验证码 换一张
取 消