在java应用程序中加载java applet
是否可以在 Java 应用程序的窗口中显示 Web 小程序?
如果你能给出一个示例代码就更好了,因为我对java相当陌生。
Is it possible to display a web applet inside a java application's window?
It would be preferable if you could give an example code, as I am rather newbish with java.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果你真的想这样做,你可以简单地将applet添加到框架中,因为Applet是Component的子类。
请注意,这是一个不好的做法,仅当您无法访问和更改小程序源代码时才应使用!你可能会遇到问题,我不能保证这会起作用。
更好的方法是创建一个包含整个视图的主面板,并将其添加到小程序或框架中,具体取决于客户端的类型(Web 或独立)。
If you really want to do this, you can simply add the applet to a frame, because Applet is a subclass of Component.
Note that this is a bad practice and should only be used if you can not access and change the applets source code! You could get into problems with it and I can not guarantee that this will work.
The better way is to create a main panel that contains the whole view and add it to the applet or frame, depending of the type of client (web or standalone).
查看 Javadocs:
Applet 是面板,因此您应该能够将它们添加到框架中。但是,它们在 Frame(或 JFrame)中的初始化和调用是不同的。顺便说一句,这是。 JApplet 版本:
如果 Applet 的代码是您的,我会将所有有趣的内容放入 JPanel 中,然后在 JApplet 中使用此 JPanel,或者将其放入 JFrame 中,并将其用作应用程序。
如果它不是您的 (J)Applet,并且您没有代码,我会尝试将它们添加到 (J)Frame 中的 (J)Panel。
Have a look into the Javadocs:
Applet are Panels, and so you should be able to add them to a Frame. However, their initialization and invocation in a Frame (or JFrame) is different. Here is, btw. the JApplet version:
If the Applet's code is yours, I would put all interesting content into a JPanel, and either use this JPanel in a JApplet, or put it into a JFrame, and use it as an application.
If it is not your (J)Applet, and you don't have the code, I would test to add them to a (J)Panel in a (J)Frame.