java applet in drupal

636 Views Asked by At

i have a java applet in a form like following

$form['applet'] = array(
  '#prefix' => '<div>',
  '#markup' => '<p align=center>
<applet codebase="." code="Clock.class" width=170 height=150>
</applet>
</p>',
  '#suffix' => '</div>',
  );

where should i place Clock.class file such that drupal always loads it.Something to do with base_path function.

3

There are 3 best solutions below

2
On

I'm not familiar with applets. But if you need to make an absolute path to it, you should place it in the module creating the form and use drupal_get_path.

In code this would look like this:

$path = drupal_get_path('module', 'MODULE_NAME');

$form['applet'] = array(
  '#prefix' => '<div>',
  '#markup' => '<p align=center>
<applet codebase="'$path'" code="Clock.class" width=170 height=150>
</applet>
</p>',
  '#suffix' => '</div>',
  );

Using the above code, you need to place the applet in the root of your custom module. You could also make a subfolder for you applet and place it there if you like. The latter is the most drupal way of doing it, but I tend to only create subfolders if I more than 3-5 files in a module.

0
On

If there are other classes and resources that need to be loaded, you probably want to replace the '.' for the codebase with the path to that directory instead of changing the path to the .class file.

Assuming your class file is part of a module in a subfolder applet, something like this should work:

... codebase = "' . drupal_get_path('module', 'yourmodule') . '/applet/" code...

(not sure if the trailing slash is necessary)

0
On

That HTML would make the JRE expect to find the class in the same directory as the web page.