Embedding a JFrame in an Applet

梦想与她 提交于 2019-12-02 09:48:26
  1. Create an instance of the frame.
  2. Get the content pane of the frame.
  3. Add the content pane to the applet.
Andrew Thompson

..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.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!