diff --git a/samples/swing2.rb b/samples/swing2.rb index 929e6d2aaac..ec94a72321f 100644 --- a/samples/swing2.rb +++ b/samples/swing2.rb @@ -5,17 +5,12 @@ frame = JFrame.new("Hello Swing") button = javax.swing.JButton.new("Klick Me!") - -class ClickAction - include java.awt.event.ActionListener - def actionPerformed(evt) - javax.swing.JOptionPane.showMessageDialog(nil, <Hello from JRuby.
+button.add_action_listener do |evt| + javax.swing.JOptionPane.showMessageDialog(nil, <Hello from JRuby.
Button '#{evt.getActionCommand()}' clicked. EOS - end end -button.add_action_listener(ClickAction.new) # Add the button to the frame frame.get_content_pane.add(button) @@ -24,6 +19,3 @@ def actionPerformed(evt) frame.set_default_close_operation(JFrame::EXIT_ON_CLOSE) frame.pack frame.visible = true - -# Sleep the main thread, so we don't exit -Thread.stop \ No newline at end of file