4

I know nothing about Java at all and I only need to run an applet on browser in localhost.

I only download the .class file from the following website

http://isgwww.cs.uni-magdeburg.de/tspanner/TSpanner.html

and I need to run this .class file on my localhost.

I tried every solution given in Java applet Error … What is wrong? but I failed to run it.

This is my HTML code

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head>
 <title>Visualization of Spanners - The Applet</title>
</head>
<body alink="#990099" bgcolor="#cccccc" link="#000099" vlink="#000099">
<applet code="gsn.TSpanner" align="BOTTOM" height="480" width="720"></applet>
</body></html>

In the directory where this .html is placed, I created a folder and renamed it to gsn and copied TSpanner.class file in there, after going to the url of the .html file Java throws the following error

NoClassDefFoundError

gsn/TSpanner (wrond name:TSpanner)

I also tried copying .class file in the root directory and setting

<applet code="TSpanner.class" align="BOTTOM" height="480" width="720"></applet>

It didn't work again.

Is it possible to run this .class in localhost? There is no more files (like .jar) and if yes how?

Thanks.

Community
  • 1
  • 1
M a m a D
  • 1,938
  • 2
  • 30
  • 61
  • The latest version of Chrome (which is what I'm using) doesn't even support Applets anymore. Alas, my capacity to help you is very limited. – Tim Biegeleisen Sep 24 '15 at 08:30
  • @TimBiegeleisen I'm using Fire Fox and after updating Java Plugin it allowed me to run it. – M a m a D Sep 24 '15 at 08:35
  • I have a detailed solution for you, q.v. my answer below. I used the `appletviewer` tool which ships with the Java JDK. If you only have the JRE, then I would recommend that you [download the JDK here](http://www.oracle.com/technetwork/java/javase/downloads/index.html). – Tim Biegeleisen Sep 24 '15 at 08:56

1 Answers1

3

I was able to get this applet to run using the appletviewer command line tool which comes with the JDK. The appletviewer tool expects you to feed it an HTML page containing an <applet> tag, so I created the following mock page for this purpose:

<HTML>
    <HEAD><TITLE>Test Page</TITLE></HEAD>
    <BODY>
    <APPLET code="TSpanner.class" align="BOTTOM" height="480" width="720"></applet>
    </BODY>
</HTML>

Save this HTML page in a directory somewhere and call it test.html. You will be using this later with the appletviewer tool.

The trick to getting it to run was to download all the class files upon which TSpanner.class is dependent. This meant downloading the following 5 class files:

  • TSpanner$AnimateThread.class
  • Path.class
  • Sheet.class
  • Point.class
  • PointVector.class

I downloaded these files from my browser by typing in the URL which Java itself would use, running from your browser, to obtain the necessary files. Here is a sample URL which I used to download the Point.class file:

http://isgwww.cs.uni-magdeburg.de/tspanner/Point.class

Do this for each of the five required class files (by simply changing the name of the class file at the end of the above URL), and save them into a directory at the same level as the test.html page which you created above.

Finally, you can run the Java appletviewer from the command line. Change directories to the bin directory of your Java installation and then run the following:

C:\Program Files\Java\jdk1.7.0_80\bin\appletviewer.exe test.html

Once it launches, you will see the applet running in its own window. Here is a screen capture of what it looked like running on my own machine:

enter image description here

You could try to get this applet to run in your Firefox browser, but unless you plan on putting this in your own webpage, appletviewer is probably the easier way to go. As you probably figured out, most browsers are dropping support for the <applet> tag at this point.

Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360
  • Thanks you very much. I am downloading the `Java SE Development Kit 8u60`, the `windows 32-bit` version. I will follow your solution and let you the results – M a m a D Sep 24 '15 at 09:02
  • One additional comment: When you run `appletviewer`, you will need to specify the _full_ location of `test.html`, wherever that might be. I think you can figure this step out yourself actually, as it has nothing to do with Java per se. – Tim Biegeleisen Sep 24 '15 at 09:03
  • Am I downloading the right software, http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html ? – M a m a D Sep 24 '15 at 09:05
  • Yes, this is the right place. Choose the appropriate download for your OS (Windows, Linux, Mac OSX). – Tim Biegeleisen Sep 24 '15 at 09:07
  • 1
    Thanks you very much. it works perfectly. thanks again. – M a m a D Sep 24 '15 at 09:35
  • 1
    *"The `appletviewer` tool expects you to feed it an HTML page containing an `` tag,"* The applet viewer will also accept a `.java` file as the argument (instead of a `.html`) so long as the applet source code file defines an applet element in a comment in the first part of the file. You can see an example (of source code with an applet element in a code comment) in the [applet info. page](http://stackoverflow.com/tags/applet/info).. – Andrew Thompson Sep 24 '15 at 13:33
  • 1
    @AndrewThompson Thanks for making this comment, Andrew. – Tim Biegeleisen Sep 24 '15 at 14:45