简体   繁体   English

我想在JPanel中放置一个JApplet

[英]I want to place a JApplet within a JPanel

as the title says, I want to place a JApplet within a JPanel, because I'm making a plugin that is supposed to show a biological diagram. 正如标题所说,我想将JApplet放在JPanel中,因为我正在制作一个应该显示生物图的插件。 The Applet itself has already been written and I've also already made a HTML tag, which also works in a browser. Applet本身已经编写完成,我也已经创建了一个HTML标记,它也适用于浏览器。 However, I don't know how to get the applet to run within the JPanel 但是,我不知道如何让applet在JPanel中运行

HTML tag: HTML标签:

<applet name="Spectrum_a" code="org/openscience/nmrshiftdb/spectrumapplet/SpectrumViewNoRenderer.class"
                codebase="/home/rianne/workspace/org.pathvisio.MetaboliteInfo/lib/"
                archive="spectrumapplet-bin-1.1.jar" width="450" height="350">
                    <param name="spectrum" value="197.74d;0.0;1|143.55;0.0;0|27.36;0.0;2t|">
                    <param name="realisticLines" value="true">
                    <param name="showCoupling" value="true">
                    <param name="hideNavigation" value="false">
                    <param name="autoIntensity" value="false">
                    <param name="solvent" value="CDCL3">
            </applet>

Hope someone can help me:) 希望可以有人帮帮我:)

To embed an applet into a Java application, I'd advise against using HTML. 要将applet嵌入到Java应用程序中,我建议不要使用HTML。 Instead, treat the applet as a simple component , and try to behave like a browser plugin towards the applet. 相反,将applet视为一个简单的组件 ,并尝试像applet的浏览器插件一样。 In particular, make sure to set a stub and call the init and start methods appropriately. 特别是,确保设置存根并调用init并适当地start方法。 It is that stub which provides parameters to the applet, so by implementing the getParameter method appropriately, you can pass whatever parameters you desire. 它是为applet 提供参数的 存根 ,因此通过适当地实现getParameter方法,您可以传递所需的任何参数。

You might have to create a separate class loader for the jar of the plugin, and instantiate the plugin class through that class loader. 您可能必须为插件的jar创建单独的类加载器 ,并通过该类加载器实例化插件类。 If your environment doesn't allow your plugin the creation of new class loaders, then you should list the applet jar as a dependency of your plugin, so that its classes are available in the same class path your plugin uses. 如果您的环境不允许您的插件创建新的类加载器,那么您应该将applet jar列为插件的依赖项,以便它的类在插件使用的相同类路径中可用。 Doing so might be the easier route even if you're allowed custom class loaders, so choose whatever approach you prefer. 即使您允许自定义类加载器,这样做可能是更容易的路径,因此请选择您喜欢的任何方法。

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

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