Skip to content

Instantly share code, notes, and snippets.

@mikaa123
Created June 12, 2012 18:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mikaa123/2919089 to your computer and use it in GitHub Desktop.
Save mikaa123/2919089 to your computer and use it in GitHub Desktop.
SWT + JRuby Bootstrap example
require 'java'
require 'swt'
# Each Swt application need a display to interact with the operating system.
# It provides the event loop.
display = Swt::Widgets::Display.new
# Let's create a new window. It's called "Shell" in Swt vocabulary.
# Note that we pass in a display.
shell = Swt::Widgets::Shell.new(display)
# Let's set the title and the size of the shell.
shell.text = "My first Swt app"
shell.set_size(200, 150)
# Each shell require a layout. It's there to organize the widgets in the shell.
layout = Swt::Layout::GridLayout.new(2, false)
shell.setLayout(layout)
# Let's create a label and add it to the parent container (the shell)
label = Swt::Widgets::Label.new(shell, Swt::SWT::NONE)
label.text = "This is a label"
button = Swt::Widgets::Button.new(shell, Swt::SWT::PUSH)
button.text = "Click Me"
button.add_selection_listener do
label.text = "clicked!"
end
# Ready to display the shell!
shell.open
# We need an event loop now.
while !shell.isDisposed
# The application sleeps unless there's a new event.
display.sleep unless display.read_and_dispatch
end
display.dispose
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment