Calling methods of an Applet from JavaScript code
import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.Label;
public class Main extends Applet {
private Label m_mess = new Label("asdf", Label.CENTER);
public void init() {
add(BorderLayout.CENTER, m_mess);
}
public void setMessage(String message) {
m_mess.setText("Selection : " + message);
}
}
<html>
<HEAD>
<TITLE>
JavaScript to Applet Communication
</TITLE >
<SCRIPT LANGUAGE="JavaScript">
function selectedCity()
{
document.SimpleMessageApplet.setMessage('hi');
}
</SCRIPT>
</HEAD>
<BODY >
<b>This is the Applet</b>
<br><br>
<APPLET CODE="MessageApplet.class" NAME="SimpleMessageApplet" WIDTH=350 HEIGHT=100 >
</APPLET >
</BODY >
</html>
Related examples in the same category