java newbie - applet code works in appletviewer, not in IE

  • jannin
  • Beginner
  • Beginner
  • User avatar
  • Posts: 40
  • Loc: Cranbrook, BC Canada

Post 3+ Months Ago

Hi all,
I've just begun to learn Java and got some super simple codes just to try it out. At the moment I've just got one of those great little "hello world" scripts. One of them is Hello.html (calls the applet) the .java file is HelloWorld.java. I compiled it (HelloWorld.class) with javac, and it works fine when I run it through appletviewer (downloaded from Sun, as with the compiler, etc etc) but if I try to run it in IE (6.0) the status bar tells me "load: class HelloWorld not found" and gives me that nice little grey box.

Like I said, complete newbie, not sure if it's the code, or IE, or what. Here are both the html and java files, and again, thanks for the help!

Hello.html:
Code: [ Select ]
<HTML>
<HEAD>
<TITLE>A Simple Program</TITLE>
</HEAD>
<BODY>
Here is the output of my program:
<APPLET CODE="HelloWorld.class" WIDTH=150 HEIGHT=25>
</APPLET>
</BODY>
</HTML>
  1. <HTML>
  2. <HEAD>
  3. <TITLE>A Simple Program</TITLE>
  4. </HEAD>
  5. <BODY>
  6. Here is the output of my program:
  7. <APPLET CODE="HelloWorld.class" WIDTH=150 HEIGHT=25>
  8. </APPLET>
  9. </BODY>
  10. </HTML>


HelloWorld.java:
Code: [ Select ]
import java.applet.*;
import java.awt.*;

/**
* The HelloWorld class implements an applet that
* simply displays "Hello World!".
*/
public class HelloWorld extends Applet {
  public void paint(Graphics g) {
    // Display "Hello World!"
    g.drawString("Hello world!", 50, 25);
  }
}
  1. import java.applet.*;
  2. import java.awt.*;
  3. /**
  4. * The HelloWorld class implements an applet that
  5. * simply displays "Hello World!".
  6. */
  7. public class HelloWorld extends Applet {
  8.   public void paint(Graphics g) {
  9.     // Display "Hello World!"
  10.     g.drawString("Hello world!", 50, 25);
  11.   }
  12. }


Thanks!
/jannin
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • _nYght
  • Novice
  • Novice
  • _nYght
  • Posts: 17

Post 3+ Months Ago

HI jannin, i copy your code and compile, and probe on mozilla 1.4 for windows and iexplorer in a winxp pro, and it works fine, many posible reasons is you don't have correctly configured your classpath or correctly instaled the jre and the java plugin .Check if you have the classpath environment variable correctly redirected to the lib directory of your jsdk

for example the mine is
Code: [ Select ]
.;C:\Program files\j2sdk_nb\j2sdk1.4.2\lib


and check the config of the explorer for java settings, in the java plug in panel and in Internet Options-> Advanced Options -> an check the box to use the sun java plug in ;)
  • jannin
  • Beginner
  • Beginner
  • User avatar
  • Posts: 40
  • Loc: Cranbrook, BC Canada

Post 3+ Months Ago

Okay...
Thanks nyght,
Here's what I discovered:
I know I have java capabilities in IE, etc etc, because I can view other java files. Also, I know that I can view java files that I have on my computer, because I downloaded an already compiled .class file, created an applet and ran it both in appletviewer and in IE. This kind of leads me to think it's the compiler, but then why will the other .java files I've compiled run in appletviewer?

/jannin
  • ATNO/TW
  • Super Moderator
  • Super Moderator
  • User avatar
  • Posts: 23456
  • Loc: Woodbridge VA

Post 3+ Months Ago

I remember helping with a similar problem awhile back:

http://www.ozzu.com/programming-forum/problems-loading-page-t20942.html

For whatever reason the applet wouldn't work in IE (same result as you have) until I installed the J2RE and used it in IE instead of the Microsoft Virtual Machine.

Hope that helps.
  • jannin
  • Beginner
  • Beginner
  • User avatar
  • Posts: 40
  • Loc: Cranbrook, BC Canada

Post 3+ Months Ago

Thanks ATNO, and sorry for the slow reply.

Checked out the J2RE, but haven't downloaded yet: if I download it and get something to work, what happens when visitors to my site try to view the applet? It wouldn't work unless they've downloaded the J2RE as well, right?

/jannin
  • ATNO/TW
  • Super Moderator
  • Super Moderator
  • User avatar
  • Posts: 23456
  • Loc: Woodbridge VA

Post 3+ Months Ago

correct
  • jannin
  • Beginner
  • Beginner
  • User avatar
  • Posts: 40
  • Loc: Cranbrook, BC Canada

Post 3+ Months Ago

Alrighty then.
I'll have to think about it I guess. Thanks for your help!

/jannin

Post Information

  • Total Posts in this topic: 7 posts
  • Users browsing this forum: No registered users and 92 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.