Something wrong with splats in my previous commit...backing out until I figure this...
[jruby.git] / samples / swing2.rb
blob929e6d2aaac7c075d200c68bfa30d03a6442684e
1 # Import Java packages
2 include Java
4 import javax.swing.JFrame
6 frame = JFrame.new("Hello Swing")
7 button = javax.swing.JButton.new("Klick Me!")
9 class ClickAction 
10   include java.awt.event.ActionListener
11   def actionPerformed(evt)
12     javax.swing.JOptionPane.showMessageDialog(nil, <<EOS)
13 <html>Hello from <b><u>JRuby</u></b>.<br> 
14 Button '#{evt.getActionCommand()}' clicked.
15 EOS
16   end
17 end
18 button.add_action_listener(ClickAction.new)
20 # Add the button to the frame
21 frame.get_content_pane.add(button)
23 # Show frame
24 frame.set_default_close_operation(JFrame::EXIT_ON_CLOSE)
25 frame.pack
26 frame.visible = true
28 # Sleep the main thread, so we don't exit
29 Thread.stop