Calling methods of an Applet from JavaScript code : Applet « Development « Java Tutorial






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>








6.28.Applet
6.28.1.Applet
6.28.2.A real applet
6.28.3.Add JButton to JApplet
6.28.4.Access applet parameters
6.28.5.An Swing-based applet skeleton
6.28.6.Swing Applet
6.28.7.A simple Swing-based applet
6.28.8.Mini Appletviewer
6.28.9.Tic Tac Toe game
6.28.10.WeatherWizard JApplet
6.28.11.Change an applet background color
6.28.12.Read an applet parameters
6.28.13.Calling methods of an Applet from JavaScript code
6.28.14.Passing Parameters to Java Applet
6.28.15.Display message in browser status bar
6.28.16.System properties accessible to applets