【发布时间】:2015-01-18 15:12:13
【问题描述】:
这是一个新手问题,但我无法在浏览器上运行一个简单的小程序。 applet 通过 eclipse 中的 appletviewer 工作,所以我知道不是这样。发生的事情是我在同一个文件夹中有 .class 和 .html 文件,并试图通过教授的服务器在浏览器上查看它们。
.html 文件
<html>
<head>
<title>Testing Applet</title>
</head>
<body>
<p>This is a test</p>
<applet code="AnAppletSubclass.class" width=150 height=100></applet>
</body>
</html>
java文件`
import java.applet.*;
import java.awt.*;
public class AnAppletSubclass extends Applet {
public void init() {
System.err.println("Hello from AnAppletSubClass.init - the current value of n is " + n);
color = Color.cyan;
}
public void paint(Graphics g) {
setBackground(color);
System.err.println("Hello from AnAppletSubClass.paint-- the current value of n is " + n);
n++;
}
Color color;
int n = 0;
}
查看小程序时发生的情况是“测试”文本出现,但我得到一个 ClassNotFoundException 和一个小程序应该位于的空白框。我不确定为什么这不起作用,因为 .class 文件编译得很好并且与 .html 在同一个文件夹中。任何帮助将不胜感激,谢谢。
【问题讨论】:
-
类在包中吗?
-
不,只是Applet的一个简单扩展,我把.java代码扔在那里。