3

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> 
1
  • 1) It would probably be both a better experience for the user, and easier, to deploy a JFrame from a link using Java Web Start. 2) The .class extension is tolerated, but not correct. 3) HTML element names should be all lower case (e.g. <html> as opposed to <Html>) 4) Is it PendulumApplet.class or Applet1.class? 5) What output do you see in the Java console? Commented Jan 22, 2012 at 3:31

4 Answers 4

1

Try below code

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

OR

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

Good Luck...

Sign up to request clarification or add additional context in comments.

2 Comments

1

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.).

Comments

0

Although I have not done so myself, my Java textbook provides this outline for an embed:

<applet code = "ClassName.class" width = 250 height = 50 [archive = archivefile] [vspace = vertical_margin] [hspace = horz_margin] [algin = applet_alignment] [alt = alt_text] > </applet>

(Optional parameters in brackets)

2 Comments

I tried what you said with the object, but when I open the webpage it says Missing Plugin and when I click that, it says there is content that cannot be displayed because its type is unspecified. Any help? (Thanks for your previous post)
I don't know... Maybe you don't have the Java plugin installed for your browser? Can you see the animated applet on this page? docs.oracle.com/javase/tutorial/uiswing/components/applet.html
0

I was having this SAME issue myself.

Using <applet code=""></applet> doesn't work, but <Applet> or <APPLET> seems to work.

Google Chrome and IE.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.