Thursday, October 4, 2012

Embedding Java Applets on Ruby on Rails

A simple way to include your applet on ruby on rails is to embedded it to your rhtml file. Use the embedding html code,

    <applet code="MyApplet.class" width="970" height="555">
</applet>

Now you need to emebedd the .class file, "YOU NEED NOT TO DO THE CODING INSIDE THE rhtml file", rather you need to embedd the compiled class file into the rhtml.

Should look like this

<html>
  <head>
    <title>
      My applet
    </title>
  </head>
  <body>
    <h2>
      Here is my applet
    </h2>
    <hr>
<center>
    <applet code="MyApplet.class" width="970" height="555">
</center>    
</applet>
    <hr>
  </body>
</html>

And not like this

<html>
  <head>
    <title>
      My applet
    </title>
  </head>
  <body>
    <h2>
      Here is my applet
    </h2>
    <hr>
<center>

import java.applet.*;
import java.awt.*;
import java.awt.event.*;
...... so on and so forth

</center>    
</applet>
    <hr>
  </body>
</html>

Note: If you do not know where to do the coding for your java applet, you can try to use Ready to Program Java IDE, it is an integrated developement environment that makes java programming easy, you can use it to code your applet and compile it to make the .class file.

Your .class file should be in the public folder.

Your_directory_here\your_ruby_on_rails_project\public

If you used any images or sounds in your applet, all the associated files with the applet for it to run correctly would be placed in the public folder too.

And things should work.

No comments:

Post a Comment