I decided to check out JRuby and JOGL to see if I could get some graphics sim stuff running. I’ve got the classpath set up and the OpenGL things included properly. Following some tutorials, they suggest using an AWT frame instead of a Swing one, as Swing won’t support graphics acceleration (which is really what I’m looking for).
I can’t figure out how to close the AWT frame from Ruby, however. I have a WindowAdapter that fires a Kernel.exit event when the close button on the frame is clicked. It looks like this:
class Controller < WindowAdapter
def windowClosing(event)
Kernel.exit
end
end
The Frame adds this with add_window_listener(Controller.new). The event successfully fires when I click the close button, but it spits out the following error:
Exception in thread "AWT-EventQueue-0" org.jruby.exceptions.RaiseException: (SystemExit) exit
Calling Kernel.exit from the Frame’s initialize successfully exits the program. So I’m not sure why calling it from the listener fails. I know in java you can define an anonymous WindowAdapter inline, but I have no idea what the syntax for that would be in Ruby.
I did some extra searching and experimentation and found an answer. It appears to be a quirk of the Ruby implementation in the JVM. Calling
exitorKernel.exitfrom inside the WindowAdapter is useless.Calling
java.lang.System.exit(0), however, does work. I’m not sure why the distinction should make a difference. I would expectexitto alias to the Java system command, but it apparently doesn’t Hope this is helpful to anyone else who might run into the same problem.