My code compiles and works just fine in both my browser and Eclipse, but for some reason the AppletViewer just won't work with my VERY simple code. When I try to run it with appletviewer FirstApplet.html
, the AppletViewer window appears as expected, but the upper-left part of the window just says "Applet" and the bottom-left part of the window says "Start: applet not initialized"
What could be the problem here? (Again, it works in my browser and Eclipse)
Thank you for any help! :)
FirstApplet.java
import java.awt.*;
import java.applet.*;
public class FirstApplet extends Applet {
public void paint(Graphics g){
g.drawString("This is my first Java Applet!", 20, 30);
}
}
FirstApplet.html
<html>
<head>
<title>FirstApplet</title>
</head>
<body>
<applet
codebase = "."
code = "FirstApplet.class"
name = "FirstApplet"
width = "640"
height = "480"
hspace = "0"
vspace = "0"
align = "middle"
>
</applet>
</body>
</html>
I figured it out! It was an Eclipse problem after all!
I wrote and compiled the code in Eclipse. Eclipse's internal version of the AppletViewer worked just fine, and it worked just fine to open the HTML file that I made in my browsers.
The applet didn't work in the actual AppletViewer, however, until I compiled the code using something other than Eclipse. It appears that for some reason AppletViewer didn't like the .class
file that Eclipse generated.
Mystery solved!