Subj : Re: Implementing Java Interfaces NOT using Rhino To : Brendan Eich From : Keno Albrecht Date : Wed Jul 14 2004 11:15 pm Hm, I see what you mean, but if I try the following example, I get the error "There is no Java method javax.swing.JButton.addActionListener that matches JavaScript argument types (object). Candidate methods with the same name are: void addActionListener(java.awt.event.ActionListener) var actionListener = { actionPerformed: function() { java.lang.System.out.println("Say Cheese"); } } var frame = new Packages.javax.swing.JFrame(); var button = new Packages.javax.swing.JButton("No Cheese, Gromit"); button.addActionListener(actionListener); frame.getContentPane().add(button); frame.setVisible(true); Do I have to cast the "actionListener" (how?) before passing it to addActionListener? Something else wrong :-)? Thanks, Keno Brendan Eich wrote: > Keno Albrecht wrote: > >> // create an array enumeration. >> var elements = new Enumeration() { >> index: 0, elements: array, >> hasMoreElements: function() { >> return (this.index < this.elements.length); >> }, >> nextElement: function() { >> return this.elements[this.index++]; >> } >> }; >> > > That's not JavaScript, not ECMA-262. You can't just write an object > initialiser after a new Foo() expression. > > >> exits with "missing ; before statement" (pointing to "new >> Enumeration() }", > > > > Good, that's the right error message. > > >> while >> >> // create an array enumeration. >> var elements = new Enumeration( { >> index: 0, elements: array, >> hasMoreElements: function() { >> return (this.index < this.elements.length); >> }, >> nextElement: function() { >> return this.elements[this.index++]; >> } >> }); >> >> (different braces!) fails with "Java class java.utils.Enumeration is >> abstract and therefore may not be instantiated" :-(. > > > > All you want is an object that has the right properties to match the > interface. You wrote that, in both examples above, when you wrote the > object initialiser. So you just need to pass that off to Java as if it > were a java.util.Enumeration. > > Here's where you need a LiveConnect guru. Cc'ing some. > > /be > >> >> >> Well, since this is a really useful feature, I would like to use it >> within my code. Any comments? >> >> Thanks, >> Keno .