如何在 GWT 页面中显示 Java 小程序? [英] How to display java applet inside GWT page?

查看:18
本文介绍了如何在 GWT 页面中显示 Java 小程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可能在这里遗漏了一些简单的东西,但我在其他地方找不到答案.我只想在我的 GWT 代码中显示一个小程序.

I'm probably missing something simple here, but I can't find the answer elsewhere. I just want to display an applet in my GWT code.

操作系统:Windows XPJava:JDK 1.6.0_10其他:GWT、GWT-Ext 2.0.5

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);
    }
}

这是调用它的代码:


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);
}

}

当我在托管模式下启动应用程序时,jvm 崩溃(向 Sun 提交事件 1425130).

When I launch the app in hosted mode, the jvm crashes (filed incident 1425130 with Sun).

当我尝试编译在浏览器中运行的 GWT 代码时,我得到了这个:

When I try to compile the GWT code for running in a browser, I get this:

        [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

显然我缺少一些小程序库,但我已经搜索了 jdk 中的所有 jar 并尝试包括所有列出 JApplet 或 awt 的那些(plugin.jar、resources.jar、rt.jar、deploy.jar、javaws.jar).

Obviously I'm missing some applet library, but I've grepped through all the jars in the jdk and tried including all of the ones that list JApplet or awt (plugin.jar, resources.jar, rt.jar, deploy.jar, javaws.jar).

另外,我很确定一旦我解决了这个问题,就会有另一个问题紧随其后,但我会把它留到另一个问题中去.

Also, I'm pretty sure once I solve this problem there's another one lurking right after it, but I'll save that for another question.

谢谢!

遗留应用程序不是小程序 - 它是一个胖客户端 Swing 应用程序.我们已将其改成小程序运行,因为我们的客户需要浏览器客户端,而这是实现这一目标的最快方式.

The legacy app is not an applet - it is a thick-client Swing application. We've hacked it to run as an applet because our customers want a browser client and this is the fastest way to get that done.

我不知道 GWT 是否会接受 JPanel 解决方案 - 该应用程序不是以 GWT 可以解析的任何方式编写的 - 即它没有使用 GWT API,而是使用 Swing API.AFAIK,将 Swing 与 GWT 混合的唯一方法是以小程序方式.

I don't know if GWT would accept the JPanel solution - the app is not written in any way that GWT can parse - i.e. it's not using the GWT API, it's using the Swing API. AFAIK, the only way to mix Swing with GWT would be in an applet fashion.

我错过了什么吗?

推荐答案

您是否正在尝试 GWT 编译您的小程序?

Are you trying to GWT-compile your applet?

这行不通,因为 GWT 编译(只是从 Java 到 Javascript 的转换)仅支持少数 Java 库,当然不支持小程序.

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.

确保您的小程序不在 GWT 源路径上(将其移动到另一个包).

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

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

这篇关于如何在 GWT 页面中显示 Java 小程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆