JApplet加载问题
我想将 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从
code
属性值的开头删除bin\
,并使用/
而不是\
(我们'我不再在华盛顿了)。如果 jar 位于名为bin
的目录中,那么您需要使用archive="bin/app.jar"
。实际上查看堆栈跟踪,jar 的构造不正确。类文件应位于目录
com/applet
中,而不是bin/com/applet
中。Remove the
bin\
from the start of thecode
attribute value, and use/
instead of\
(we're not in Washington anymore). If the jar is in a directory namedbin
then you'll need to usearchive="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
, notbin/com/applet
.