简体   繁体   English

将JFrame嵌入到Applet中

[英]Embedding a JFrame in an Applet

I have found an open source application that creates a JFrame to display some content. 我发现一个开源应用程序创建了一个JFrame来显示一些内容。 I would 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? 我想将此JFrame “嵌入”到applet中,因此Jframe中显示的所有内容都将显示在applet中-这可能吗?

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.. ..创建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). 由于源可用,因此请在框架中执行所有操作,然后在applet中进行操作(有一些细微的变体和陷阱)。

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. 程序员可能已将GUI设置为在构造函数中可见,这意味着如果不在屏幕上显示自由的浮动GUI元素,就无法访​​问内容窗格。
  2. Custom painting direct to the frame (eeek). 自定义绘画直接到框架(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. 框架程序员通常将EXIT_ON_CLOSE用作框架的退出行为。 It is not permitted (or necessary) for a sand-boxed applet to end the VM. 不允许(或不必要)使用沙盒小程序结束VM。 Even a trusted applet would (and should) normally be prevented from calling System.exit(int) . 即使是受信任的applet,也通常(并且应该)被阻止调用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. 基于框架的代码通常会执行需要信任applet的事情,或者需要替代策略来实现相同的目标。

Points 3 & 4 are less applicable/relevant if the frame was designed to be launched using web start. 如果框架是使用Web Start启动的,则第3点和第4点不太适用/不重要。 And since I mention webstart.. 因为我提到了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. 请注意,“转换”要使用Java Web Start启动的框架通常比创建和部署小程序或将框架转换为小程序要容易。 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. 除非applet的某些功能对应用程序至关重要且不可用(鉴于您是从该应用程序开始的,所以这不太可能),否则我建议启动该应用程序。 via JWS, rather than doing a conversion. 通过JWS,而不是进行转换。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM