Javascript and Applet interaction
| Articles |
So we want our javascripts to make use of Java objects. In the previous page we discussed the HTML tags that signal our intent to the browser. Now we will look at the code that actually does the job.
The applet from the previous page has been modified so that it will listen to javascript calls. In actual fact several modifications have been made but the only one that matters is the addition of a public method that will update the JTextArea of the applet when called. It's a one liner but only because we have not considered factors like thread safety for the sake of simplicity and clarity.
public void setText(String s)
{
txt.setText(s);
}
The applet is compiled and embedded into this web page, along with a simple HTML form.




