简体   繁体   中英

Simple Java Applet Display Via Browser Error

This is a newbie question but I am having trouble running a simple applet on a browser. The applet works via the appletviewer in eclipse so I know it's not that. What is going on is that I have the .class and .html files in the same folder and am trying to view them on a browser via the professor's server.

the .html file

<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 file`

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;
}

What happens when viewing the applet is that the "test" text appears but I am getting a ClassNotFoundException and a blank box where the applet should be. I'm unsure why this isn't working since the .class file is compiled fine and in the same folder as the .html. Any help would be appreciated, thanks.

将codebase属性添加到applet标签:

codebase="." 

它不起作用的原因是由于权限,以防万一有人看到它并感到好奇,只需要一个简单的chmod a + r * .class就可以了。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM