Solved

loading applet on web browser

Posted on 2003-11-24
11
691 Views
Last Modified: 2013-11-23
hi!

I am trying to load applet on web browser.
I placed HelloApplet.class and HelloApplet.html same dir(home_dir/public_html/../..).
However, when I tried to load by typing "http://www....../HelloApplet.html,
just "Hello, Applet World!" from HelloApplet.html file appears, and there is
no string or clickable button on the browser. It just shows gray area...that's it.
Why is that?

Thanks for help.

//---------------------
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class HelloApplet extends JApplet {

   private int currentIndex = 0;
   
   public void init() {
      final String[] MESSAGES = {"Hello, Applet World!","Still here"};
      final JLabel DISPLAY_LABEL = new JLabel("");
      JButton showButton = new JButton("Click here for a message " +
                                 "from our sponsor!");
      showButton.addActionListener(new ActionListener() {
         public void actionPerformed(ActionEvent e) {
            DISPLAY_LABEL.setText(MESSAGES[currentIndex]);
            currentIndex = (currentIndex + 1) % MESSAGES.length;
         }
      });
      Container contentPane = getContentPane();
      contentPane.add(showButton, BorderLayout.NORTH);
      contentPane.add(DISPLAY_LABEL, BorderLayout.CENTER);
   }
}

//-------------------------

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
  <title>Hello, Applet World!</title>
</head>
<body>
<h1>Hello, Applet World!</h1>
<br>

<applet code="HelloApplet.class" width="400" height="100">
Error, your browser does not understand applet tags!
</applet>

</body>
</html>
0
Comment
Question by:dkim18
  • 5
  • 4
  • 2
11 Comments
 
LVL 15

Assisted Solution

by:dualsoul
dualsoul earned 170 total points
ID: 9815846
you are using MSIE did you? :)

you haven't enable Sun Java Plug-IN for runnig applets, so IE tries to run your applet, using it's own olm Microsoft JVM 1.1 , and this JVM doesn't know about new Swing classes and so on.

 So go to control panel, run Java Plugin and click enable :)
it's work fine with Plug-In
0
 

Author Comment

by:dkim18
ID: 9816091
Thank you for your answer, but I don't see Enable Java Plug-in option on Basic Panel and any other panel.
0
 
LVL 35

Expert Comment

by:TimYates
ID: 9816741
The "Advanced" panel?

It's about half way down the list of checkboxes
0
 
LVL 35

Expert Comment

by:TimYates
ID: 9816744
Sorry...

Tools -> Internet Options -> Advanced
0
 
LVL 35

Expert Comment

by:TimYates
ID: 9816746
Of course, you will need the plugin from http://java.sun.com/getjava if you don't already have it...
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:dkim18
ID: 9817582
I tried all, but it wasn't successful. I don't know why...
When I try to run, I see "java.lang.NoClassDefFoundError:HelloApplet$1." on bottom of web broswer.
0
 
LVL 35

Assisted Solution

by:TimYates
TimYates earned 80 total points
ID: 9817609
Have you copied all your class files?

Sounds like you have inner/anonymous classes in your applet, and you aren't copying their class files to the webserver...

Tim
0
 

Author Comment

by:dkim18
ID: 9817756
I ftp HelloApplet$1.class as well and the applet starts, but I still don't see clickable button and messages"
What is difference "HelloApplet$1.class" and "HelloApplet.class"? When I compiled, I got both classes file.
There is no inner class in my applet by the way.(from above source)

I 'd apprecatied your comments
0
 
LVL 35

Assisted Solution

by:TimYates
TimYates earned 80 total points
ID: 9817897
showButton.addActionListener(new ActionListener() {
         public void actionPerformed(ActionEvent e) {
            DISPLAY_LABEL.setText(MESSAGES[currentIndex]);
            currentIndex = (currentIndex + 1) % MESSAGES.length;
         }
      });

is an anonymous inner class

what shows up on the java console when you try to load the applet?

try CTRL-Refresh instead of just refresh to load the applet...

That clears the cache...
0
 

Author Comment

by:dkim18
ID: 9819703
It shows up "Hello, Applet World!" and the bottom web broswer says 'Applet HelloApplet Started and then if I mouse my mouse to gray box then the msg chagnes to 'loading java applet...' and it takes forever.  I did try CTRL-Refresh option, but didn't work.
Is it server problem? I asked to a friend of mine to load the applet and he got same problem...
0
 
LVL 15

Accepted Solution

by:
dualsoul earned 170 total points
ID: 9820335
dkim18, look, i've tested your applet with MSIE and Netscape, with installed Sun Java PlugIN, it works fine :)

so download J2SDK 1.4.2 from java.sun.com, install it (don't forget to check Java Plug-in for IE and Netscape), and all should work fine.

if you haven't java plug-in , your IE will use Microsoft Old JVM 1.1, so your applet won't work. Certanly you can compile it for JVM 1.1, like this:
      java -target 1.1 *.java
, but i think your Swing classes won't be found, cause Microsoft JVM too old and don't know about it.

> I ftp HelloApplet$1.class as well and the applet starts, but I still don't see clickable button and messages"

you should upload all .class files, there will be 2 files in your case

by the way, do you tested it on local machine? does it work?
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This video teaches viewers about errors in exception handling.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now