-
-
Notifications
You must be signed in to change notification settings - Fork 942
Description
The file at:
https://github.com/jruby/jruby/blob/master/samples/swing2.rb
I believe line 4 should be changed from:
import javax.swing.JFrame
to:
java_import javax.swing.JFrame
Otherwise a (harmless) warning is shown right now.
On a side note, I am currently trying to create and use an entry for
user input via jruby + swing (the JTextField) and find out how to
respond to "if user hit the enter key in the entry, call a method".
The swing2.rb kind of has a way to show how this is done via:
button.add_action_listener do |evt|
javax.swing.JOptionPane.showMessageDialog(nil, <<EOS)
<html>Hello from <b><u>JRuby</u></b>.<br>
Button '#{evt.getActionCommand()}' clicked.
EOS
But I don't know whether this will work for JTextField. Will try
to find out.
If someone feels like wanting to do extra work, it would be nice
if swing2.rb could be renamed to swing.rb or swing_example.rb
and extended with a few more widgets. Right now I am trying
to gather information from java, but the syntax is often not
easy to translate 1:1 for me for jruby+swing. In my own ruby-gtk3
code, for instance, I tend to simplify all of this via:
button.on_clicked {
}
Or:
entry.on_enter_key_pressed {
}
Not sure if jruby wants to add custom DSLs (since it is more work
I get it), but I find from a usability point of view this is so much easier
to work with. Via the add_action_listener I have to kind of simulate
the java swing API in ruby and this is not always trivial or convenient
IMO. What could help indirectly would be more examples in jruby
but these are quite hard to find. I find many more examples in java
(unsurprisingly so); for instance https://java-swing-tips.blogspot.com/
it is a really good website with TONS of code + screenshots, but it
is quite hard to translate this all back into ruby. Perhaps rubocop will
auto-correct other languages into java too one day ... :D Anyway, this
issue request is mostly about the typo, but if someone wants to improve
on swing2.rb and/or rename, that may also be nice - just as a demo
in one file. (I get that it was last modified some ~14 years ago or so...)