I have an extremely basic Java applet that isn't functioning in Safari as an exercise for an old textbook that isn't working. I'm using the legacy Java SDK version 1.6 on OSX El Capitan. The HTML is
<html>
<head>
<title>2-1 Test</title>
</head>
<body>
<applet code="HelloWorld.class"></applet>
</body>
</html>
And the Java program is:
import java.awt.*;
import java.applet.*;
public class HelloWorld extends java.applet.Applet{
TextField m1, m2, m3;
public void main(){
m1 = new TextField(60);
m2 = new TextField(60);
m3 = new TextField(60);
m1.setText("Good day to you!");
m2.setText("My name is Cynthia.");
m3.setText("This is the third line.");
add(m1);
add(m2);
add(m3);
}
}
HTML and Java file (compiled to HelloWorld.class) are in the same directory (no packages are involved).
UPDATE: Spaces have been removed from the filepath. The Java console now came up with the following:
basic: tap installed
basic: Creating PluginEmbeddedFrame served by PlaceHolderServerName-2581
basic: Done creating PluginEmbeddedFrame
basic: Added progress listener: sun.plugin.util.ProgressMonitorAdapter@7e29e923
security: Expected Main URL: file:/Users/Desktop/GreatIdeasInComputerScienceWithJavaExercises/HelloWorld.class
java.lang.ClassNotFoundException: HelloWorld.class
at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass0(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Unknown Source)
at sun.plugin2.applet.Plugin2Manager.initAppletAdapter(Unknown Source)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
at java.lang.Thread.run(Thread.java:745)
basic: load: class HelloWorld.class not found.
java.lang.ClassNotFoundException: HelloWorld.class
at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass0(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Unknown Source)
at sun.plugin2.applet.Plugin2Manager.initAppletAdapter(Unknown Source)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
at java.lang.Thread.run(Thread.java:745)
security: Accessing keys and certificate in Mozilla user profile: null
security: Reset deny session certificate store
security: Reset deny session certificate store
basic: Removed progress listener: sun.plugin.util.ProgressMonitorAdapter@7e29e923
basic: Dialog type is not candidate for embedding
basic: Dialog type is not candidate for embedding
Can anyone suggest what I would need to do to get Java set up properly so I can continue with the book?
Take what's in your main
method and place it in the init
or run
method. Applets typically don't have main
methods.
Having said all that, applets are now deprecated and are generally no longer supported, with most if not all browsers actively blocking them and Oracle's decision to remove support for the applet plugin.
Maybe you should have a closer look at How to use Applets
Updated
Now that the error has changed, it would suggest that you've not compiled the .java
file and/or it's not compiled in the location you're expecting it