Very Simple Swing GUI does not work

I try to build a very simple GUI, in fact a JFrame which only contains a
button which is clickable, but it doesnt work properly. The GUI is
visible, but when I try to click the button, an error occurs.

My code:
#Just a helping method
def include_classes(*classes)
classes.each do |element|
include_class(element)
end
end

require “java”
include_classes “javax.swing.JFrame”, “java.awt.event.ActionListener”

class MyFrame < JFrame
include ActionListener #in order to implement the interface

def initialize
#Initializing the frame
super(“JRuby!”)
setSize(600, 200)
setLayout(java.awt.FlowLayout.new)
setDefaultCloseOperation(JFrame::EXIT_ON_CLOSE)

#Configuring and adding the button
button = javax.swing.JButton.new("Click!")
getContentPane.add(button)
button.addActionListener(self)

setVisible(true)

end

#think of an @Override here
def actionPerformed(event)
print “apfelnerd”
end
end

#Running
MyFrame.new

The beforementioned error is attached to this post.

You are trying to call ‘print’ in actionPerformed and that is a method
in Frame which expects a Graphic parm. The error threw me at first
too, but in retrospect it is an ok error message.

-Tom

On Tue, May 4, 2010 at 12:25 PM, Obernerd Surenerd
[email protected] wrote:

end
super(“JRuby!”)
end
The beforementioned error is attached to this post.
http://xircles.codehaus.org/manage_email


blog: http://blog.enebo.com twitter: tom_enebo
mail: [email protected]


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Thomas E Enebo wrote:

You are trying to call ‘print’ in actionPerformed and that is a method
in Frame which expects a Graphic parm. The error threw me at first
too, but in retrospect it is an ok error message.

Thanks a lot; recently I had another error akin to this one (in Java), I
think it was when I tried to add a draw method in a inherting hierachry
starting with JComponent :slight_smile: