6 Replies - 9602 Views - Last Post: 10 January 2011 - 07:41 AM Rate Topic: -----

#1 DilshanUOM   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 08-January 11

Embed java applet in blogger blog posts

Posted 10 January 2011 - 12:37 AM

Help me to embed a java applet in my blog.

I tried to add a simple java applet to one of my blog posts.

Java applet code - Used for testing
package hello;

/*hello.java*/
import java.awt.Graphics;
public class Main extends java.applet.Applet
{
public void paint(Graphics g)
{
g.drawString("Hello Java!", 30, 30);
}
}


First I uploaded my jar file to my Google site.
Link: https://sites.google.../home/hello.jar

Then I added the following code to my post editor.

<applet codebase="https://sites.google.com/site/dilshanuom/home/"
height="100" archive="hello.jar" width="200" code="hello.class">
<param name="_cx" value="2646"><param name="_cy" value="2646"></applet>


There was no error while saving the post.(I've previously tried few other ways, which caused errors while saving)

However, when i preview my post, there was an error as shown bellow. :cry2:

Error in details
Java Plug-in 1.6.0_22
Using JRE version 1.6.0_22-b04 Java HotSpot(TM) Client VM
User home directory = C:\Users\Administrator
----------------------------------------------------
c:   clear console window
f:   finalize objects on finalization queue
g:   garbage collect
h:   display this help message
l:   dump classloader list
m:   print memory usage
o:   trigger logging
q:   hide console
r:   reload policy configuration
s:   dump system and deployment properties
t:   dump thread list
v:   dump thread stack
x:   clear classloader cache
0-5: set trace level to <n>
----------------------------------------------------


sun.plugin2.main.client.PluginMain: unrecognized message ID 42
sun.plugin2.main.client.PluginMain: unrecognized message ID 42
load: class hello.class not found.
java.lang.ClassNotFoundException: hello.class
	at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
	at sun.plugin2.applet.Plugin2ClassLoader.loadClass0(Unknown Source)
	at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
	at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Unknown Source)
	at sun.plugin2.applet.Plugin2Manager.createApplet(Unknown Source)
	at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
	at java.lang.Thread.run(Unknown Source)
Caused by: java.io.IOException: open HTTP connection failed:https://sites.google.com/site/dilshanuom/home/hello/class.class
	at sun.plugin2.applet.Applet2ClassLoader.getBytes(Unknown Source)
	at sun.plugin2.applet.Applet2ClassLoader.access$000(Unknown Source)
	at sun.plugin2.applet.Applet2ClassLoader$1.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	... 9 more
Exception: java.lang.ClassNotFoundException: hello.class
load: class hello.class not found.
java.lang.ClassNotFoundException: hello.class
	at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
	at sun.plugin2.applet.Plugin2ClassLoader.loadClass0(Unknown Source)
	at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
	at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Unknown Source)
	at sun.plugin2.applet.Plugin2Manager.createApplet(Unknown Source)
	at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
	at java.lang.Thread.run(Unknown Source)
Caused by: java.io.IOException: open HTTP connection failed:https://sites.google.com/site/dilshanuom/home/hello/class.class
	at sun.plugin2.applet.Applet2ClassLoader.getBytes(Unknown Source)
	at sun.plugin2.applet.Applet2ClassLoader.access$000(Unknown Source)
	at sun.plugin2.applet.Applet2ClassLoader$1.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	... 9 more
Exception: java.lang.ClassNotFoundException: hello.class




Are there anyone who has done this successfully before?

Please help me to correct the code, or show any other way to do it.



My Blog : http://inftec-dilshanuom.blogspot.com/

This post has been edited by DilshanUOM: 10 January 2011 - 12:40 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Embed java applet in blogger blog posts

#2 cfoley   User is offline

  • Cabbage
  • member icon

Reputation: 2392
  • View blog
  • Posts: 5,025
  • Joined: 11-December 07

Re: Embed java applet in blogger blog posts

Posted 10 January 2011 - 03:03 AM

public class Main extends java.applet.Applet


code="hello.class"


A class called Main, when compiled will give a file called Main.class. You need to refer to Main.class in your applet code.

I haven't written an applet in about ten years but since you're using packages you may have to include that information in the applet tag too. Something like hello.Main.class or hello/main.class. Like I say, I've not done it for a while so I'm not sure exactly how to make the HTML tag.
Was This Post Helpful? 1
  • +
  • -

#3 DilshanUOM   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 08-January 11

Re: Embed java applet in blogger blog posts

Posted 10 January 2011 - 05:17 AM

Thanks for pointing out my silly mistake. :blush:


<applet codebase="https://sites.google.com/site/dilshanuom/home/" 
height="100" archive="hello.jar" width="200" code="Main.class">
<param name="_cx" value="2646"><param name="_cy" value="2646"></applet>



But anyway, even after I changed the code it didn't work.

Error:
Java Plug-in 1.6.0_22
Using JRE version 1.6.0_22-b04 Java HotSpot(TM) Client VM
User home directory = C:\Users\Administrator
----------------------------------------------------
c:   clear console window
f:   finalize objects on finalization queue
g:   garbage collect
h:   display this help message
l:   dump classloader list
m:   print memory usage
o:   trigger logging
q:   hide console
r:   reload policy configuration
s:   dump system and deployment properties
t:   dump thread list
v:   dump thread stack
x:   clear classloader cache
0-5: set trace level to <n>
----------------------------------------------------


load: class Main.class not found.
java.lang.ClassNotFoundException: Main.class
	at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
	at sun.plugin2.applet.Plugin2ClassLoader.loadClass0(Unknown Source)
	at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
	at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Unknown Source)
	at sun.plugin2.applet.Plugin2Manager.createApplet(Unknown Source)
	at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
	at java.lang.Thread.run(Unknown Source)
Caused by: java.io.IOException: open HTTP connection failed:https://sites.google.com/site/dilshanuom/home/Main/class.class
	at sun.plugin2.applet.Applet2ClassLoader.getBytes(Unknown Source)
	at sun.plugin2.applet.Applet2ClassLoader.access$000(Unknown Source)
	at sun.plugin2.applet.Applet2ClassLoader$1.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	... 9 more
Exception: java.lang.ClassNotFoundException: Main.class


Was This Post Helpful? 0
  • +
  • -

#4 cfoley   User is offline

  • Cabbage
  • member icon

Reputation: 2392
  • View blog
  • Posts: 5,025
  • Joined: 11-December 07

Re: Embed java applet in blogger blog posts

Posted 10 January 2011 - 05:55 AM

You still haven't told the applet tag which package the class is in. You should either place the class in the default package or google how to specify which package the main class is in.

The latter is the recommended option.
Was This Post Helpful? 1
  • +
  • -

#5 g00se   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3640
  • View blog
  • Posts: 16,733
  • Joined: 20-September 08

Re: Embed java applet in blogger blog posts

Posted 10 January 2011 - 06:28 AM

Your applet tag needs to be as follows:


	<applet codebase="https://sites.google.com/site/dilshanuom/home/"
	height="100" archive="hello.jar" width="200" code="hello.Main">
	<param name="_cx" value="2646"><param name="_cy" value="2646"></applet>


Was This Post Helpful? 1
  • +
  • -

#6 DilshanUOM   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 08-January 11

Re: Embed java applet in blogger blog posts

Posted 10 January 2011 - 06:39 AM

Thanks again for your help.
I've googled it and I found the answer. :bigsmile:
The only thing I missed was specifying the package.

Now it works.

<applet codebase="https://sites.google.com/site/dilshanuom/home/" height="100" archive="hello.jar" width="200" code="hello.Main.class"><param name="_cx" value="2646"><param name="_cy" value="2646"></applet>

Was This Post Helpful? 0
  • +
  • -

#7 cfoley   User is offline

  • Cabbage
  • member icon

Reputation: 2392
  • View blog
  • Posts: 5,025
  • Joined: 11-December 07

Re: Embed java applet in blogger blog posts

Posted 10 January 2011 - 07:41 AM

Glad you got it sorted. :-)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1