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!
- Create an instance of the frame.
- Get the content pane of the frame.
- 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:
- 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.
- 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.
- 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 callingSystem.exit(int)
. - 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.
精彩评论