1

I am trying to make a simple Applet, and it is proving far more challenging than I expected.

I have the following, very basic applet:

import java.applet.*;
import java.awt.*;

public class HelloWorldApplet extends Applet
{
   public void paint (Graphics g)
   {
      g.drawString ("Hello World", 25, 50);
   }
}

created in notepad and saved as:

HelloWorldApplet.java

then in the same folder I have the following HTML file:

<html>
<title>The Hello, World Applet</title>
<hr>
<applet code="HelloWorldApplet.class" width="320" height="120">
If your browser was Java-enabled, a "Hello, World"
message would appear here.
</applet>
<hr>
</html>

created in notepad and saved as:

HelloWorldApplet.html

I am getting the following error when trying to load the page:

ClassNotFoundException

HellowWorldApplet.class

Java is installed on the machine and from all the tutorials and reading I have done, everything is exactly correct.

Any ideas??

3
  • How did you compiled your code? Commented Jan 13, 2015 at 9:23
  • @manish I havent it is all done in notepad Commented Jan 13, 2015 at 9:25
  • 1
    u have to compile it in order to get .class file. open cmd prompt if using win or terminal in linux like OS. go to the file location using cd and then compile using javac "filename". It will create a .class file in your current directory. Commented Jan 13, 2015 at 9:28

1 Answer 1

3

Embed the following code in the applet file as a multiline comment.

Eg:

/*
<applet code="HelloWorldApplet.class" width="320" height="120"></applet>
*/

save this as "HelloWorldApplet.html"

Compile using javac command

javac HelloWorldApplet.java

for Run the program using appletviewer command

appletviewer HelloWorldApplet.html

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.