-2

I used appletviewer to verify my code. It is right.

When I use IE to display html including applet, why the IE just display the content from the html not from applet ? here is the code:

Java: 

import java.awt.Graphics;

public class HelloWorldApplet extends java.applet.Applet{

public void paint (Graphics g)
{
  g.drawString("HelloWorld", 5, 25);
}
}


Html:
<html>
<head>
<title>Hello to Everyone</title>
</head>
<body >
<P>Why?
<APPLET CODE= "java.awt.Graphics.HelloWorldApplet" WIDTH=150 HEIGHT=25></APPLET>
</body>
</html>

In addition: I put the HelloWorldApplet.java and HelloWorldApplet.class and HelloWorldApplet.html fils in the same directory

Roman C
  • 49,761
  • 33
  • 66
  • 176

2 Answers2

0

The code attribute doesn't look right. Is your class really in a package called java.awt.Graphics? Graphics is a class in the existing package java.awt.

It looks like your code is not in a package, so it should be code="HelloWorldApplet.class".

rgettman
  • 176,041
  • 30
  • 275
  • 357
  • I tried it again based on your suggestion. Another situation is that it appears an alert saying "blocked exception..."by using IE. So what is wrong with it ? Thanks a lot! – user2616444 Jul 24 '13 at 23:36
  • this code is an example from the book named "teach myself in java in 21 days". Actually, the code on the book is what you wrote. I made some change based on other infor. – user2616444 Jul 24 '13 at 23:41
0

If your applet is in a different package other than the default, you'd want to use something like: code="org.me.hello.MyApplet"

A good applet tutorial can be found at: https://netbeans.org/kb/docs/web/applets.html

Amaranda
  • 30
  • 4