0

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.

ayush
  • 14,350
  • 11
  • 53
  • 100

3 Answers3

1

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.

googletorp
  • 33,075
  • 15
  • 67
  • 82
  • You might want to make the codepass argument dynamic instead of code, because that will be used by java to load additional resources like files and other classes. – Berdir Mar 14 '11 at 17:01
  • @Berdir: Updated the code. Haven't worked with Java applets, so didn't know about addition files. – googletorp Mar 14 '11 at 18:50
1

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)

Berdir
  • 6,881
  • 2
  • 26
  • 38
1

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

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433