Search code examples
javahtmlswingpackagingjapplet

applet not working on browser


I'm following some exercises on how to build applets; however, I'm not able to get it to show up in the browser. After trying for several times, and being sure that the applet was correct and so was the html page (both on same folder). I downloaded the same version of my applet from the author website (class + html) put them both in a folder and they worked. The strange thing is that both file are identical to mine, but mine aren't working... anyone could suggest what could be wrong? here are both of my files (very simple)

here the link to the applet on the web http://www.cs.armstrong.edu/liang/intro8e/book/DisplayLabel.html

here are my files

html file

<html>
  <head>
    <title>Java Applet Demo</title>
  </head>
  <body>
    <applet
      code = "DisplayLabel.class"
      width = 250
      height = 50>
    </applet>
  </body>
</html>

class file (java code)

package Chapter18Applets;

import javax.swing.JApplet;
import javax.swing.JLabel;

public class DisplayLabel extends JApplet {

    public DisplayLabel() {
        add(new JLabel("This is an Applet!", 0));
    }
}

Solution

  • package Chapter18Applets;
    

    Remove that line. You are not using a package, so you don't need a package declaration.