I'm trying to create a basic Java applet that will display the output of my Java program in a web browser.
Having never worked with applets before, I thought I would follow a tutorial to try and create a simple "Hello World" applet, just to get a simple understanding of how they work.
I am using the example at: http://www.cs.nccu.edu.tw/~linw/javadoc/tutorial/getStarted/applet/index.html and have followed the steps exactly as described.
However, when I compile the Java source file, although a "HelloWorld" class file appears in my 'Project Explorer' window in Eclipse, I cannot see the class file at all when viewing the root project folder in Windows Explorer- all I see there is my HelloWorld.java file, and Hello.html file.
When I run the HelloWorld.java class in Eclipse, although I get a warning in the console that says:
Warning: Can't read AppletViewer properties file: C:.... Using defaults
the application does run- and a little window pops up titled "AppletViewer:...HellowWorld.class". This window has an 'Applet' menu, with menu items such as Restart, Reload, Stop, Save, etc, and the window displays "Hello World!" in the location specified, and a message saying "Applet started." at the bottom.
But, when I try to view the webpage in a browser, I get a message that says: "Error. Click for details" where the "Hello World" message should be displayed...
My HelloWorld.java class has the code:
package openDis.applet;
import java.awt.Graphics;
public class HelloWorld extends java.applet.Applet {
public void init() {
resize(150,25);
}
public void paint(Graphics g) {
g.drawString("Hello world!", 50, 25);
}
}
and the HTML in the webpage I'm trying to use to display the message is:
<html>
<head>
<title>A Simple Program</title>
</head>
<body>
Here is the output of the program:
<applet code="HelloWorld.class" width=150 height=25></applet>
</body>
</html>
What am I doing wrong here? What do I need to do to get the output of the program to display in the web page? Thanks for any help in advance!