JRubyでSWTを試す
JRubyでswtを試してみます。
JRuby+swtの情報がなかなか無いですが、とりあえずメモします。
まずは、swtライブラリの準備です。
swtはEclipseのライブラリなのでJRubyには含まれていません。なので別途準備が必要です。
swt.jarは以下URLから取ってこれます。
http://www.eclipse.org/swt/
swt-4.2-win32-win32-x86.zip にswt.jarが含まれています。
swt.jarをスクリプトと同じディレクトリに置いてください。
今回スクリプトとしては以下を準備しました。
require 'java' module SwtTest SWT = org.eclipse.swt.SWT Display = org.eclipse.swt.widgets.Display Shell = org.eclipse.swt.widgets.Shell Button = org.eclipse.swt.widgets.Button Label = org.eclipse.swt.widgets.Label Listener = org.eclipse.swt.widgets.Listener RowLayout = org.eclipse.swt.layout.RowLayout display = Display.new shell = Shell.new(display) button = Button.new(shell, SWT::PUSH) button.text = "Push Me" label = Label.new(shell, SWT::NONE) label.text = "hello!!!" label.set_size(100,75) button.addListener(SWT::Selection, Listener.impl do |method, event| label.text = 'clicked button.' end) shell.layout = RowLayout.new shell.set_size(200,100) shell.open until shell.is_disposed do display.sleep unless display.read_and_dispatch end display.dispose end
実行は、以下のとおりです。
% jruby -r swt.jar swt_test.rb