英文:
Java Swing Applet - Class not found exception when running appletviewer
问题
我使用Netbeans设计了一个使用Swing的JApplet。类的头部如下所示:
public class GUI2 extends javax.swing.JApplet
文件P2.jar生成在P2/dist中,我创建了以下P2.html文件。该文件位于P2/dist中,与P2.jar相同的位置。
<html>
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<center>
<applet
code="GUI2.java"
width="500"
height="500">
</applet>
</center>
</body>
</html>
我导航到P2/dist并执行以下命令:
appletviewer -J"-Djava.security.policy=applet.policy" P2.html
applet.policy 包含运行该小程序所需的权限。在执行后,我得到了以下异常:
java.lang.ClassNotFoundException: GUI2.java
at sun.applet.AppletClassLoader.findClass(AppletClassLoader.java:220)
at java.lang.ClassLoader.loadClass(ClassLoader.java:419)
at sun.applet.AppletClassLoader.loadClass(AppletClassLoader.java:153)
at java.lang.ClassLoader.loadClass(ClassLoader.java:352)
at sun.applet.AppletClassLoader.loadCode(AppletClassLoader.java:637)
at sun.applet.AppletPanel.createApplet(AppletPanel.java:801)
at sun.applet.AppletPanel.runLoader(AppletPanel.java:730)
at sun.applet.AppletPanel.run(AppletPanel.java:379)
at java.lang.Thread.run(Thread.java:748)
执行后,该小程序显示:小程序未初始化。
英文:
I designed a JApplet (with Swing) using Netbeans. The class' header looks as follows:
public class GUI2 extends javax.swing.JApplet
The file P2.jar is generated in P2/dist and I created the following P2.html file. Said file is located in P2/dist, same place as P2.jar
<html>
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<center>
<applet
code="GUI2.java"
width="500"
height="500">
</applet>
</center>
</body>
</html>
I navigate to P2/dist and execute the following command:
appletviewer -J"-Djava.security.policy=applet.policy" P2.html
applet.policy contains the needed permissions to run the applet. I'm getting the following exception after executing:
> java.lang.ClassNotFoundException: GUI2.java at
> sun.applet.AppletClassLoader.findClass(AppletClassLoader.java:220) at
> java.lang.ClassLoader.loadClass(ClassLoader.java:419) at
> sun.applet.AppletClassLoader.loadClass(AppletClassLoader.java:153) at
> java.lang.ClassLoader.loadClass(ClassLoader.java:352) at
> sun.applet.AppletClassLoader.loadCode(AppletClassLoader.java:637) at
> sun.applet.AppletPanel.createApplet(AppletPanel.java:801) at
> sun.applet.AppletPanel.runLoader(AppletPanel.java:730) at
> sun.applet.AppletPanel.run(AppletPanel.java:379) at
> java.lang.Thread.run(Thread.java:748)
After executing, said Applet shows: applet not initialized
专注分享java语言的经验与见解,让所有开发者获益!
评论