How to display java applet inside GWT page?

Something is probably missing me, but I cannot find the answer elsewhere. I just want to display the applet in my GWT code.

OS: Windows XP Java: JDK 1.6.0_10 Other: GWT, GWT-Ext 2.0.5

Here is the applet (obviously simplified for testing):

package foo.applet; import javax.swing.JApplet; import java.awt.Graphics; public class HelloApplet extends JApplet { public void paint(Graphics g) { g.drawRect(0, 0, getSize().width - 1, getSize().height - 1); g.drawString("Hello world!", 5, 15); } } 

Here is the code that calls it:

 package foo.applet; import com.google.gwt.user.client.ui.HTML; import com.gwtext.client.widgets.Panel; public class AppletPanel extends Panel { 
 public AppletPanel() { HTML applet = new HTML(); applet.setHTML("<applet name=\"HelloApplet\" code=\"HelloApplet.class\" width=\"300\" height=\"300\"" ); this.add(applet); } 

}

When I run the application in host mode, jvm crash (recorded incident 1425130 with the Sun).

When I try to compile GWT code to work in a browser, I get the following:

  [ERROR] Errors in 'file:/C:/<blah>/applet/HelloApplet.java' [ERROR] Line 3: The import javax.swing cannot be resolved [ERROR] Line 4: The import java.awt cannot be resolved [ERROR] Line 6: JApplet cannot be resolved to a type [ERROR] Line 8: Graphics cannot be resolved to a type [ERROR] Line 11: The method getSize() is undefined for the type HelloApplet [ERROR] Line 12: The method getSize() is undefined for the type HelloApplet 

Obviously, I am missing some library of applets, but I went through all the jdk banks and tried to include all those that list JApplet or awt (plugin.jar, resources.jar, rt.jar, deploy.jar, javaws.jar).

In addition, I am sure that when I solve this problem, there is another one hiding right after it, but I will save it for another question.

Thanks!


An outdated application is not an applet - it is a Swing application with a thick client. We hacked it to work as an applet, because our clients need a browser client, and this is the fastest way to do this.

I don’t know if GWT will decide JPanel - the application is not written in any way that GWT can analyze - that is, it does not use the GWT API, it uses the Swing API. AFAIK, the only way to mix Swing with GWT will be in applets.

Did I miss something?

+4
source share
6 answers

Are you trying to compile your GWT applet?

This will not work, since compiling GWT (it is just a translation from Java to Javascript) supports only a few Java libraries and, of course, not applets.

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

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

+6
source

Do not use GWTCompiler to compile applet code. I would recommend creating a second module (or project) containing only applet code. Compile this into a separate JAR using the standard Javac compiler (or your IDE / ant)

GWTCompiler uses a subset of Java libraries and should only be used to generate code that will eventually run as Javascript.

+4
source

Google found this one . One answer reads: β€œThe previous poster is right, the shell cannot handle embedded things like Flash or Applets. There are some limitations in the SWT component used to launch the browser inside the shell. The error report was related to this problem, you may want to keep an eye on her for future updates. "

It seems like this is impossible.

+1
source

I found this while researching for a gwt application, and although this is an old thread, I thought I'd send a method to run the applet inside gwt.

First create two different projects: one for your applet and one for gwt . make your applet as usual.

Add your applet.

then sign .jar with jarsigner .

create your gwt modules as usual.

to implement the applet, I use the gwt HTML object with the applet tag as follows:

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

Just add the HTML widget to the contentPanel and the gui part will be executed.

The .jar applet will need to be run in / war for your gwt project.

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

This will allow you to embed the applet in gwt and run it in host or production mode. The key is to WRITE your .jar and run it with .jnlp

+1
source

The lightweight application can mix GWT and JNLP. Then we could get larger banks in cars for people quite transparently. As an example, I would like to use the Batik toolkit or other SVG-related tools to have SVG in my GWT application, and not force me to use only png or other raster formats.

  • Tyro - you can also send your thoughts on this subject to bob.futrelle@gmail.com
0
source

"Importing javax.swing is not possible" - sorry, I'm not a GWT maven, but this error is classpath-esque. It seems that GWT cannot find rt.jar for your JVM.

-1
source

All Articles