how to implement java interfaces in javascript
1 posts in topic
Flat View  Flat View

Posted By:   Yuriy_Halytskyy
Posted On:   Thursday, January 17, 2008 02:33 PM

Is it possible to implement java interfaces in javascript and pass them as parameters to applet methods? For example applet has addActionListener as a method and I want to implement ActionListener in javascript.

Some javascript engines allow to create anonymous classes but I wasn't able to do this from browser.


Re: how to implement java interfaces in javascript

Posted By:   Stephen_McConnell  
Posted On:   Saturday, January 19, 2008 07:52 PM

Classes in Java and Classes in JavaScript are not compatible and are not even the same thing.

That doesn't mean that you cannot use JavaScript to call methods on a Java Applet and pass it "String" representation of the information you what to pass.

I'd did that about 8 years ago, but haven't had the need to do that since. However, with the growing use of ActiveX Objects and Java Applets in Browsers with JavaScript (what do you think AJAX is?) it's becoming more fashionable.

When you define an Applet in HTML, you need to use the tags to describe Java Object. There are ways (I've forgotten them) to describe methods that you need to access those methods.

How Java to Javascript Communication Works in Java Plug-in is an article on how this works. This is about Java 1.3, but I would think it still works similar.

Stephen McConnell