Java & JavaScript. How to connect them?
Do you know that you can call Java-Applet-public-methods from JavaScript?
I don't really know how you can use it, but it works.
For example, you have applet:
Working sample:
I don't really know how you can use it, but it works.
For example, you have applet:
import javax.swing.JApplet;
import javax.swing.JLabel;
public class TestApplet extends JApplet {
JLabel lbl;
public void setLabelText(String text) {
lbl.setText(text);
}
public void init() {
lbl = new JLabel("This is java-applet");
this.getContentPane().add(lbl);
}
}
If you want to change text in applet with javascript, you can use code:
<APPLET code="TestApplet.class" width=240 height=40 id="myapplet"></APPLET>
<FORM>
<INPUT TYPE="text" value="Enter text here" id="myTextField">
<INPUT type=button value="Insert to applet" onclick="CallAppletMethod()">
<SCRIPT>
function CallAppletMethod() {
var myApplet = document.getElementById('myapplet');
var myParam = document.getElementById('myTextField').value;
myApplet.setLabelText(myParam); //just call java-method, it's easy :)
}
</SCRIPT>
Working sample:

good
Posted by VEERA on July 22, 2009 at 01:00 PM GMT+03:00 #
hai
Posted by ram on July 22, 2009 at 01:25 PM GMT+03:00 #