How to display java applet inside GWT page?

≯℡__Kan透↙ 提交于 2019-11-30 22:49:00

Are you trying to GWT-compile your applet?

This won't work, as GWT compilation (which is just translation from Java to Javascript) supports only handful of Java libraries and certainly not applets.

Make sure that your applet is not on GWT source path (move it to another package).

Reference: http://code.google.com/docreader/#p=google-web-toolkit-doc-1-5&s=google-web-toolkit-doc-1-5&t=RefJreEmulation

Don't use the GWTCompiler to compile your applet code. I would recommend creating a second module (or project) that contains only the applet code. Compile this to a separate JAR using the standard Javac compiler (or your IDE/ant)

The GWTCompiler uses a subset of the Java libraries, and should only be used to generate the code which is going to eventually run as Javascript.

Google found this. One of the responses says: "The previous poster is right, the shell can not handle embedded things like Flash or Applets. There are some restrictions in the SWT component used to run the browser inside of the shell. A bug report has been associated with this issue, you may want to keep an eye on it for future updates."

Looks like it can't be done.

Josh

I found this during research for a gwt app, and even though this is an old thread thought i would post a method to run an applet inside of gwt.

First create two distinct projects, one for your applet and one for gwt. make your applet as normal.

jar your applet.

then SIGN your .jar with jarsigner.

create your gwt modules as normal.

to embed the applet I use a gwt HTML object with an applet tag like this:

(applet MAYSCRIPT code = 'com.myapplet.MyApplet' id ='myApplet' jnlp_href = '/spplets/MyApplet.jnlp', width=500, height=400)(/applet)

Simply add the HTML widget to a contentPanel and the gui part is done.

The applet .jar will need to go in the /war for your gwt project.

Along with the .jar you will need to write a .jnlp file to launch the applet.

This will embed an applet in gwt and run it in hosted or production mode. The key is to SIGN your .JAR and launch it with .JNLP

A light-heavyweight app might mix GWT and JNLP. Then we could get the bigger jars onto people's machines rather transparently. As an example, I'd like to use the Batik toolkit or other SVG-related goodies to have SVG in my GWT app, rather than being forced to use only png or other raster formats.

  • Tyro - you can also mail your thoughts on this to me at bob.futrelle@gmail.com

"The import javax.swing cannot be resolved" - sorry, I'm not a GWT maven, but this error is classpath-esque. Sounds like GWT can't find the rt.jar for your JVM.

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