Skip to content

Instantly share code, notes, and snippets.

@opamp
Created August 10, 2011 02:43
Show Gist options
  • Save opamp/1135966 to your computer and use it in GitHub Desktop.
Save opamp/1135966 to your computer and use it in GitHub Desktop.
Swing_test-JRuby
#!/usr/local/bin/ruby --1.9
#-*- encoding: utf-8 -*-
require 'java'
import 'javax.swing.JFrame'
import 'javax.swing.JButton'
import 'javax.swing.JTextField'
import 'javax.swing.JTextArea'
import 'javax.swing.JPanel'
import 'java.awt.BorderLayout'
class ButtonAction
include java.awt.event.ActionListener
def initialize(area,text)
@ar = area
@tx = text
end
def actionPerformed(evt)
@ar.append(@tx.getText())
end
end
frame = JFrame.new("MainWindow")
button = JButton.new("OK")
text = JTextField.new(15)
area = JTextArea.new()
area.setRows(15)
area.setColumns(20)
button.add_action_listener(ButtonAction.new(area,text))
panel = JPanel.new
panel.add text
panel.add button
panel.add area
frame.getContentPane.add(panel, BorderLayout::CENTER)
frame.setDefaultCloseOperation(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