Friday, December 2, 2011

Embed Java Applets into a Google Site

I have been rebuilding my class website as a Google site this year. There are many, many things that I love about the new Google site, but it took my awhile to figure out how to embed Java applets. Here is how I finally got it to work.

Step 1: Create a page on your Google site to hold the .class files. I made a "file cabinet" page and then simply uploaded all of the .class files there.

Step 2: Prepare your HTML snippet. Here is what I used. Notice that I set the CODEBASE to the directory that is associated with the "file cabinet" page. I needed to do this because my Applet used multiple .class files. If you only had one .class file you could put the absolute address to that class file with the CODE attribute and leave out the CODEBASE attribute.

<APPLET CODE="DancingStickFigureApplet.class"
ALT="Your browser understands the <APPLET> tag but isn't running the applet, for some reason.">
Your browser is ignoring the <APPLET> tag!

Step 3: Put the Applet into the page. DO NOT PASTE THE APPLET HTML INTO THE PAGE. A Google site page does not allow this. Instead, you need to embed it as a gadget. While your page is open for editing, select Insert-->More Gadgets. You are looking for the gadget called “Embed Gadget.” I found it faster by selecting “Featured Gadgets.” Paste in the Applet code into the gadget dialog box and you are done!

Here is my web page showing a working Applet with a dancing stick figure. :-)


  1. thanks a lot sir, its working, i used it to put java applets game on google sites

  2. Hi,
    Trying to load the demo page you linked above, I get an error of:
    "incompatible magic value 1011373133 in class file DancingStickFigureApple"

    This happens also when I try the method you descibe above with an applet of my own.
    Do you have any idea how to solve this?

    I'm using both FF & IE9 to test this.


  3. It took me quite a while to figure out what I was doing wrong, and it turned out I was using "http://" rather than "https://". Thank you very much! Super helpful, and much simpler than any other help I've found. Thank you very much!

  4. Thanks for the post about this topic. Storing the files in a Google Sites file cabinet is not working for me, at least not when my applet tries to load sounds from a JAR that's in the file cabinet on Google Sites. I was seeing access permission errors, with sockets, etc. Googling the error message revealed no hits, and so I enabled full debugging in the Java Runtime console. I saw that Google caches the actual files on different servers (oddly named servers like The failure was occurring in the getAudioClip call... I believe the codebase isn't fixed when you use this approach.

    What I did to make it work was to upload the JAR to a repository (it's an extra step to create it). Referring to that space as a codebase from Google Sites is OK.