You can also subclass and implement one or more interfaces at the same time, e.g.
# you probably wouldn't combine these particular
# interfaces,
just an example
class MyFrame < javax.swing.JFrame
include java.awt.event.ActionListener include java.lang.Runnable
def initialize(*args)
super @button = new javax.swing.JButton 'Click me'
add @button @button.add_action_listener self
#..etc end
def actionPerformed(event)
#... end
def run #...
endendYou can also group interfaces that you frequently use together:
module RunCompare
include java.lang.Runnable
include java.lang.Comparable
end
class AClass
include RunCompare
def run
#...
end
def compareTo(other)
#..
end
end
-Bill
On 8/15/07,
Peter K Chan <peter@...> wrote:
Ken,
The new way is to use "include" to include the Java interface, as if
it is a Ruby module.
For example:
Class RunnableRuby
include java.lang.Runnable
def run
puts :Running
end
end
Peter
-----Original Message-----
From: Kenneth McDonald [mailto:kenneth.m.mcdonald@...]
Sent: Wednesday, August 15, 2007 11:57 PM
To: user@...
Subject: [jruby-user] What is the current syntax for defining a class in
JRuby that implements a Java interface?
I've seen an 'old' way to do it, but suspect there is something more
modern. Is there a page anywhere that gives quick examples of how to do
Java-specific stuff in JRuby?
Thanks,
Ken
---------------------------------------------------------------------
To unsubscribe from this list please visit:
http://xircles.codehaus.org/manage_email
---------------------------------------------------------------------
To unsubscribe from this list please visit:
http://xircles.codehaus.org/manage_email