2

I'm trying to add a Java applet to my display.html for my new question type.

But unfortunately an error appears, that myapplet.class not found. In fact it is on the same folder with display.html and when I run the display.html alone the applet appears, only it doesn't appear when I run the question type inside Moodle. Here is the code for the applet:

import java.awt.TextArea;
import javax.swing.JApplet;

/**
 *
 * @author Islam
 */
public class myapplet extends JApplet {

    /**
     * Initialization method that will be called after the applet is loaded
     * into the browser.
     */
    TextArea tx;
    public void init() {
        // TODO start asynchronous download of heavy resources
        tx=new TextArea();
        tx.setSize(100, 200);
        add(tx);
    }

    // TODO overwrite start(), stop() and destroy() methods

}

And here is the code of the display.html

 <html>
<div class="qtext">
  <?php echo $questiontext; ?>
</div>

<div class="ablock clearfix">
  <div class="prompt">
    <?php echo $stranswer; ?>
  </div>
  <table class="answer"><tr><td><?php // HTML editors have to go in tables. ?>
    <?php echo $answer; ?>
  </td></tr></table>
  <applet code=myapplet.class name=myapplet archive=applet.jar width=1000 height=500>Your browser is not Java enabled.</applet>

<param name="bgcolor" value="ffffff">
<param name="fontcolor" value="000000">
Your browser is not Java enabled.
</applet>

  <br />
  <?php if ($feedback) { ?>
    <div class="feedback">
      <?php echo $feedback; ?>
    </div>
  <?php } ?>
  <?php $this->print_question_submit_buttons($question, $state, $cmoptions, $options); ?>
</div>
</html>
Paŭlo Ebermann
  • 73,284
  • 20
  • 146
  • 210
islam
  • 47
  • 1
  • 3
  • `tx.setSize(100, 200);` 1) The size of a `JTextArea` can be suggested by using the constructor that accepts numbers of rows and columns. 2) The preferred size of a component is more often used by layouts, than it's size. 3) Since this is the only component in an applet, points 1 & 2 are redundant. The size of the text area is set by HTML. **As an aside** Applets are more difficult than applications. What is your specific need for an applet? – Andrew Thompson May 31 '11 at 01:04
  • "when I run the display.html alone" HTML is not executable so that statement is nonsense. Do you mean displaying the HTML in a browser, as opposed to the applet viewer? "myapplet.class not found in fact it is on the same folder with display.html" That applet element specifies an `applet.jar` so it is inside the archive that the JRE will be expecting to find the `myapplet.class`. – Andrew Thompson May 31 '11 at 01:09
  • Thanks Andrew for your reply and I hope you can help me. First yes actually I mean displaying the HTML in browser.Second what did you mean by "That applet element specifies an applet.jar so it is inside the archive that the JRE will be expecting to find the myapplet.class" can you explain farther – islam May 31 '11 at 01:28
  • Is there an `applet.jar` in the same directory as the HTML? Is there a `myapplet.class` inside the root of the `applet.jar`? – Andrew Thompson May 31 '11 at 01:31
  • yes there is an applet.jar in same directory as the HTML but I can't figure what did you mean by "Is there a myapplet.class inside the root of the applet.jar" what did you mean by root of applet.jar?? sorry for being annoy. – islam May 31 '11 at 01:36

1 Answers1

2

Your first line has the applet close tag </applet>.

Try this instead:

<applet
    code="myapplet.class"
    name="myapplet"
    archive="applet.jar"
    width="1000"
    height="500">

  <param name="bgcolor" value="ffffff">
  <param name="fontcolor" value="000000">
  Your browser is not Java enabled.
</applet>
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Alexander Pogrebnyak
  • 44,836
  • 10
  • 105
  • 121