Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

loading applet on web browser

Posted on 2003-11-24
11
Medium Priority
?
735 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 2
11 Comments
 
LVL 15

Assisted Solution

by:dualsoul
dualsoul earned 680 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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 320 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 320 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 680 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
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 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 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:
Suggested Courses

722 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