Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display an applet in a webpage using HTML/JavaScript

I have very little experience with HTML and applets. I have tried several of the things I found online, but am unable to make my Java applet run in a web browser (it functions in eclipse).

I have put the HTML file in the same folder as all of my Java class files for the applet. I am currently using Safari, but would like the applet to work in most any popular browser.

How can I display a java applet on a webpage using HTML/JavaScript? Can anyone offer any tips/advice?

Below is my attempted HTML code.

Attempt 1:

<Html>
<Head>
<Title>Pendulum Applet</Title>
</Head>
<Body>
<br>
<br>
<embed code="PendulumApplet.class"
  width="200" height="200"
  type="application/x-java-applet;version=1.5.0"
  pluginspage="http://java.sun.com/j2se/1.5.0/download.html"/></embed>
</Body>
</Html>

Attempt 2:

<Html>
<Head>
<Title>Pendulum Applet</Title>
</Head>

<Body>
<br>
<br>
<OBJECT 
  classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
  width="200" height="200">
  <PARAM name="code" value="Applet1.class">
</OBJECT>
</Body>
</Html> 
like image 877
user1163061 Avatar asked Dec 06 '25 12:12

user1163061


2 Answers

Try below code

 <APPLET CODE=AppletSubclass.class WIDTH=anInt HEIGHT=anInt>
 </APPLET>

OR

 <object width="400" height="400" data="helloworld.class"></object> 

Good Luck...

like image 82
Fahim Parkar Avatar answered Dec 09 '25 02:12

Fahim Parkar


Use deployJava.js to write the applet element. The script is supported by Oracle, and will:

  1. Check the user has the minimum required Java, prompting them to install if not, before..
  2. Writing the object/embed or applet element as is best known for that browser.

Other notes:

  1. Is it PendulumApplet.class or Applet1.class? It is hard enough to debug problems on international forums without introducing doubt about the name of the applet class.
  2. The .class extension in the code attribute is tolerated, but not correct. The value should be a string representing the Fully Qualified Name of the class. E.G. javax.swing.JApplet as opposed to javax.swing.JApplet.class.
  3. HTML element names should be all lower case (e.g. <html> as opposed to <Html>)
  4. What output do you see in the Java console? When debugging applets in a browser, it is vital ensure the Java Control Panel is configured to pop open the console on discovering an applet (or JWS app.).
like image 45
Andrew Thompson Avatar answered Dec 09 '25 00:12

Andrew Thompson