Modern web pages include a wide variety of dynamic content, incorporating the use of HTML,
To start with, code your Java applet as normal. There are no special considerations to make, other other than ensuring that the function to be called is defined as public. For instance, here is a simple function that will display a message box, showing any text passed in the szMessage parameter to the user.
JOptionPane:showMessageDialog(null, szMessage, "Hello!", JOptionPane.INFORMATION_MESSAGE);
}
Compile your java file, and include it in your web page using standard HTML tags. (It is worth highlighting at this point that, if you are using a code obfuscator such as Proguard, you will need to specify that the function name be preserved after the obfuscation process).
Now, to call that function from Java, you create an HTML hyperlink in the form:
For those unfamiliar with HTML, this code creates what appears to be a standard HTML link. However, instead of changing the page, when the user clicks on the link, the browser executes a piece of
When the user clicks on the link, the correct Java function will be executed, in this case rendering a message box to the screen. As a final note, it is worth mentioning that, on tighter security settings, some browser do limit the ability of
Post a Comment