Solved

loading applet on web browser

Posted on 2003-11-24
11
703 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
topping1 challenge 7 73
Strange loading of website behaviour 3 32
servlet doXXX methods 3 39
map related example 6 38
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

863 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

23 Experts available now in Live!

Get 1:1 Help Now