Right,
Hello abcl developers,
Let's say I want to implement an anonymous inner class, just for example ActionListener with method actionPerformed:
JButton button = new JButton("Enter"); button.addActionListener(new ActionListener (){ public void actionPerformed(ActionEvent e){
System.out.println("The Enter button was pressed"); } });
What is the best way to do this in abcl?
Cheers, Patrice
On Tue, Aug 16, 2011 at 4:09 PM, Alan Ruttenberg alanruttenberg@gmail.comwrote:
On Tue, Aug 16, 2011 at 3:55 PM, Patrice Seyed apseyed@gmail.com wrote:
How about a boolean?
(make-immediate-object nil :boolean) (make-immediate-object t :boolean)
Next, I'm trying to work my way up to defining anonymous inner classes from within abcl.
That's a bit more problematic, at least for me. Can you write up a specific small code example you want to implement and send a note the armedbear-devel@common-lisp.net asking for what the recommended approach would be?
-Alan
Patrice
On Mon, Aug 15, 2011 at 5:53 PM, Alan Ruttenberg < alanruttenberg@gmail.com> wrote:
null = (make-immediate-object nil :ref)
On Mon, Aug 15, 2011 at 4:06 PM, Patrice Seyed apseyed@gmail.com wrote:
Alan,
If I wanted to pass as an argument that I would specify as null in java, from abcl to java, how would I do that?
For example a method called method1 that takes two argument that I want to pass a string and the second argument null:
(#"method1" 'ClassName "string" nil)
If I specify nil as i did here I get a java exception "argument type
mismatch".
Patrice
On Tue, Aug 16, 2011 at 10:27 PM, Patrice Seyed apseyed@gmail.com wrote:
Right,
Hello abcl developers, Let's say I want to implement an anonymous inner class, just for example ActionListener with method actionPerformed: JButton button = new JButton("Enter"); button.addActionListener(new ActionListener (){ public void actionPerformed(ActionEvent e){
System.out.println("The Enter button was pressed"); } }); What is the best way to do this in abcl?
Hi Patrice,
Welcome to the ABCL list! "implementing an anonymous inner class" is ambiguous: when in Java you write an inner class, you do so to implement an interface or to extend another class. Inner classes are only a Java-the-language (javac) construct, but for the JVM they're classes like any others. So, your question should be: how do I implement an interface (like ActionListener) in ABCL? How do I extend a class (like MouseAdapter) in ABCL? For the first question, there are two operators: jmake-proxy and jinterface-implementation. The first is newer and more powerful but less documented. You can find both of them in the file java.lisp in ABCL's sources. For the simple case of interfaces with a single method (SAM - single abstract method) you can do like this (untested): (jmake-proxy "java.awt.event.ActionListener" (lambda (obj method event) (declare (ignore obj method)) (handle-my-event event)))
For the second question, there's currently no way to define new Java classes in Lisp. Technically it's doable and not particularly hard, but nobody did it yet. (ABCL used to support it long time ago). I was supposed to look into it some time ago but never found the actual time for doing it.
Hope that answers your question - if not, do not hesitate to write back!
Cheers, Alessio
On Aug 16, 2011, at 23:39 , Alessio Stalla wrote:
[…]
For the first question, there are two operators: jmake-proxy and jinterface-implementation. The first is newer and more powerful but less documented.
There is [a fairly detailed example of how to use JINTERFACE-IMPLEMENTATION in an answer on stackoverflow that might aid understanding][1].
[1]: http://stackoverflow.com/questions/4785969/can-you-write-a-java-class-with-a...
[…]
For the second question, there's currently no way to define new Java classes in Lisp. Technically it's doable and not particularly hard, but nobody did it yet. (ABCL used to support it long time ago). I was supposed to look into it some time ago but never found the actual time for doing it.
We [have an issue filed][#126] to track the (re)implementation of this feature, but as Alessio mentioned no one is currently actively attempting to implement it at this point. The [source to the old implementation is actually still present in our source tree][2] but we would probably rewrite the use of ASM to using our newer JVM class writing infrastructure so it wouldn't be dependent on additional jars.
[#126]: http://trac.common-lisp.net/armedbear/ticket/126 [2]: http://trac.common-lisp.net/armedbear/browser/trunk/abcl/src/org/armedbear/l...
-- "A screaming comes across the sky. It has happened before, but there is nothing to compare to it now."
armedbear-devel@common-lisp.net