0
votes

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.

2
Is the class in a package?Reimeus
no, just a simple extension of Applet, i threw the .java code up there.user3587186

2 Answers

0
votes

Add the codebase attribute to your applet tag:

codebase="." 
0
votes

the reason it didnt work was because of permissions, in case anyone looks at this and is curious, just needed a simple chmod a+r *.class and it worked.