Skip to content

Instantly share code, notes, and snippets.

@headius
Last active July 26, 2019 02:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save headius/5dca771a8a09c7ee5aa331f1406a97ad to your computer and use it in GitHub Desktop.
Save headius/5dca771a8a09c7ee5aa331f1406a97ad to your computer and use it in GitHub Desktop.
# Import Java packages
include Java
java_import javax.swing.JFrame
frame = JFrame.new("Hello Swing")
button = javax.swing.JButton.new("Klick Me!")
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
end
# Add the button to the frame
frame.content_pane.add(button)
# Show frame
frame.default_close_operation = JFrame::EXIT_ON_CLOSE
frame.pack
frame.visible = true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment