Created
June 12, 2012 18:12
-
-
Save mikaa123/2919089 to your computer and use it in GitHub Desktop.
SWT + JRuby Bootstrap example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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