//<applet code=FirstApplet width=100 height=100>
//</applet>
package com.davidflanagan.examples.applet;
import java.applet.*; // Don't forget this import statement!
import java.awt.*; // Or this one for the graphics!
/** This applet just says "Hello World! */
public class FirstApplet extends Applet {
// This method displays the applet.
public void paint(Graphics g) {
g.drawString("Hello World", 25, 50);
}
}
输出如下:
E:\java>appletviewer FirstApplet.java
载入:找不到类 FirstApplet。
java.lang.ClassNotFoundException: FirstApplet
at sun.applet.AppletClassLoader.findClass(AppletClassLoader.java:168)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.applet.AppletClassLoader.loadClass(AppletClassLoader.java:119)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at sun.applet.AppletClassLoader.loadCode(AppletClassLoader.java:599)
at sun.applet.AppletPanel.createApplet(AppletPanel.java:712)
at sun.applet.AppletPanel.runLoader(AppletPanel.java:641)
at sun.applet.AppletPanel.run(AppletPanel.java:320)
at java.lang.Thread.run(Thread.java:595)
Caused by: java.io.FileNotFoundException: E:\java\FirstApplet.class (系统找不到
指定的文件。)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:106)
at java.io.FileInputStream.<init>(FileInputStream.java:66)
at sun.net.www.protocol.file.FileURLConnection.connect(FileURLConnection
.java:70)
at sun.net.www.protocol.file.FileURLConnection.getInputStream(FileURLCon
nection.java:161)
at sun.applet.AppletClassLoader.getBytes(AppletClassLoader.java:280)
at sun.applet.AppletClassLoader.access$100(AppletClassLoader.java:44)
at sun.applet.AppletClassLoader$1.run(AppletClassLoader.java:158)
at java.security.AccessController.doPrivileged(Native Method)
at sun.applet.AppletClassLoader.findClass(AppletClassLoader.java:155)
... 8 more
谁能告诉我是为什么吗?
----------------解决方案--------------------------------------------------------
package com.davidflanagan.examples.applet;
被我去了
是不是我的路径设的有问题啊
我的classpath
C:\Program Files\Java\jdk1.5.0_04\lib\tools.jar;C:\Program Files\Java\jdk1.5.0_04\lib\rt.jar
----------------解决方案--------------------------------------------------------
好像还没编译吧?
----------------解决方案--------------------------------------------------------
appletviewer 后面应该跟html文件名而不是java文件!!!
----------------解决方案--------------------------------------------------------
编译applet小程序的顺序应该是,例如你上面的那个文件,javac FirstApplet.java 然后 appletviewer html文件名
这个html文件你 <applet code=FirstApplet.class width=100 height=100></applet>文件
----------------解决方案--------------------------------------------------------