Skip to content

Instantly share code, notes, and snippets.

@jasonrclark
Created October 17, 2015 04:37
Show Gist options
  • Save jasonrclark/a85f6c057d652c39a1f3 to your computer and use it in GitHub Desktop.
Save jasonrclark/a85f6c057d652c39a1f3 to your computer and use it in GitHub Desktop.
Using swt gem directly
#! /usr/bin/env jruby
require 'swt'
#module Swt
#include_package 'org.eclipse.swt.graphics'
#include_package 'org.eclipse.swt.events'
#include_package 'org.eclipse.swt.dnd'
#module Events
#import org.eclipse.swt.events.PaintListener
#import org.eclipse.swt.events.MouseMoveListener
#end
#module Widgets
#import org.eclipse.swt.widgets.Canvas
#end
#end
class SwtExample
def initialize
# A Display is the connection between SWT and the native GUI.
display = Swt::Widgets::Display.get_current
@shell = Swt::Widgets::Shell.new
@shell.text = "Example"
# A Shell must have a layout. FillLayout is the simplest.
layout = Swt::Layout::FillLayout.new
@shell.setLayout(layout)
@shell.set_size 200, 200
@shell.add_paint_listener do |event|
event.gc.draw_text "Yo", 0, 0
end
# And this displays the Shell
@shell.open
end
# This is the main gui event loop
def start
display = Swt::Widgets::Display.get_current
# until the window (the Shell) has been closed
while !@shell.isDisposed
# check for and dispatch new gui events
display.sleep unless display.read_and_dispatch
end
display.dispose
end
end
Swt::Widgets::Display.set_app_name "Example"
app = SwtExample.new
app.start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment