require 'java'
import 'javax.swing.JFrame'
import 'javax.swing.JLabel'
import 'javax.swing.SwingUtilities'
import 'java.lang.Runnable'
class SwingDemo
def initialize
jfrm = JFrame.new "A Simple Demo"
jfrm.setSize(275,100)
jfrm.default_close_operation = JFrame::EXIT_ON_CLOSE
jlab = JLabel.new " Swing powers the modern Java GUI"
jfrm.add jlab
jfrm.pack
jfrm.visible = true
end
end
class RunnableProc
include Runnable
def initialize(&block)
@block = block
end
def run
@block.call
end
end
class Proc
def to_runnable
RunnableProc.new &self
end
end
SwingUtilities.invoke_later(proc { SwingDemo.new }.to_runnable)