JApplet加载问题

发布于 2024-08-30 05:23:20 字数 2040 浏览 4 评论 0原文

我想将 java 应用程序转换为 applet,但在浏览器中加载它时遇到问题,我认为这是因为 package.json 文件的原因。


package com.applet;

import java.applet.Applet;

import javax.swing.JApplet;
import javax.swing.SwingUtilities;
//import javax.swing.JOptionPane;

@SuppressWarnings("serial")
public class AppletDriver extends Applet {

    //Called when this applet is loaded into the browser.
    public void init() {
        //Execute a job on the event-dispatching thread; creating this applet's GUI.
        try {
            SwingUtilities.invokeAndWait(new Runnable() {
                public void run() {
                    CleanerPanel cFrame = new CleanerPanel();
                    add(cFrame); 
                }
            });
        } catch (Exception e) {
            System.err.println("createGUI didn't complete successfully");
        }
    }
}

这是我用来调用小程序的代码,当我在 Eclipse 中运行它时,它正在工作。 这是 html 代码:

<applet archive="app.jar" code="bin/com/applet/AppletDriver.class" width=350 height=200>
</applet>

app.jar 位于 eclipse 项目的主目录中,有什么建议吗?

来自浏览器java控制台的错误:

java.lang.NoClassDefFoundError: bin/com/applet/AppletDriver (wrong name: com/applet/AppletDriver)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(Unknown Source)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknown Source)
    at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Unknown Source)
    at sun.plugin2.applet.Plugin2Manager.createApplet(Unknown Source)
    at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Exception: java.lang.NoClassDefFoundError: bin/com/applet/AppletDriver (wrong name: com/applet/AppletDriver)

I want to convert an java application to applet, but I an having problems to load it in the browser I presume this is because of the package.


package com.applet;

import java.applet.Applet;

import javax.swing.JApplet;
import javax.swing.SwingUtilities;
//import javax.swing.JOptionPane;

@SuppressWarnings("serial")
public class AppletDriver extends Applet {

    //Called when this applet is loaded into the browser.
    public void init() {
        //Execute a job on the event-dispatching thread; creating this applet's GUI.
        try {
            SwingUtilities.invokeAndWait(new Runnable() {
                public void run() {
                    CleanerPanel cFrame = new CleanerPanel();
                    add(cFrame); 
                }
            });
        } catch (Exception e) {
            System.err.println("createGUI didn't complete successfully");
        }
    }
}

this is the code I am using to call the applet when I run it in Eclipse it is working.
this is the html code:

<applet archive="app.jar" code="bin/com/applet/AppletDriver.class" width=350 height=200>
</applet>

the app.jar is in the main dir of the eclipse project any suggestions ?

error from browser java console:

java.lang.NoClassDefFoundError: bin/com/applet/AppletDriver (wrong name: com/applet/AppletDriver)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(Unknown Source)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknown Source)
    at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Unknown Source)
    at sun.plugin2.applet.Plugin2Manager.createApplet(Unknown Source)
    at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Exception: java.lang.NoClassDefFoundError: bin/com/applet/AppletDriver (wrong name: com/applet/AppletDriver)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

陈独秀 2024-09-06 05:23:20

code 属性值的开头删除 bin\,并使用 / 而不是 \ (我们'我不再在华盛顿了)。如果 jar 位于名为 bin 的目录中,那么您需要使用 archive="bin/app.jar"

实际上查看堆栈跟踪,jar 的构造不正确。类文件应位于目录 com/applet 中,而不是 bin/com/applet 中。

Remove the bin\ from the start of the code attribute value, and use / instead of \ (we're not in Washington anymore). If the jar is in a directory named bin then you'll need to use archive="bin/app.jar".

Actually looking at the stack trace, the jar has been constructed incorrectly. The class file should be in a directory com/applet, not bin/com/applet.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文