How to run java.class applet in browser on localhost

I don't know anything about Java at all and I just need to run the applet in the browser at localhost.

I only download the file .class

from the following website

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

and I need to run this file .class

on my localhost.

I have tried every solution given in the Java applet Error ... What's wrong? but I was unable to start 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 one resides .html

, I created a folder and renamed it to gsn

and copied the TSpanner.class

file there, after navigating to the url of the file .html

. Java throws the following error

NoClassDefFoundError

gsn / TSpanner (handwritten name: TSpanner)

I also tried to copy the file .class

to the root directory and install

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

      

It didn't work again.

Can I run this one .class

on localhost? There are no more files (for example .jar

) and if so, how?

Thank.

+3


source to share


1 answer


I was able to run this applet using the command line tool appletviewer

that comes with the JDK. The tool appletviewer

expects you to send it an HTML page containing the tag <applet>

, so I created the following layout 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 name it test.html

. You will use this later with a tool appletviewer

.

The trick for running it was to load all the class files it depends on TSpanner.class

. This meant loading 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 a URL that Java itself will use, running from your browser, to get the files I need. Here's an example URL that I used to download the file Point.class

:

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

      



Do this for each of the five required class files (by simply changing the class file name at the end of the above url) and store them in a directory at the same level as the page test.html

you created above.

Finally, you can start Java appletviewer

from the command line. Change directories in bin

your Java installation directory and do the following:

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

      

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

enter image description here

You can try to run this applet in your Firefox browser, but if you don't plan on hosting it on your own web page, there appletviewer

is probably an easier way. As you've probably figured out, most browsers drop support for the tag <applet>

at this point.

+3


source







All Articles