Solved

loading applet on web browser

Posted on 2003-11-24
11
719 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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
 

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
hibernate example for saving data 19 52
Detect Closed Loops (circles, figure-8s, etc) in PNG Images 6 56
Chrome and Firefox Java 5 49
how to debug htl and js pages 8 38
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
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:

791 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