Jump to: navigation, search

Difference between revisions of "JRuby/SWTSnippets/Snippet1.rb"

Line 8: Line 8:
 
#
 
#
 
# Contributors:
 
# Contributors:
#     IBM Corporation - initial API and implementation
+
#   IBM Corporation - initial API and implementation
 
################################################################################
 
################################################################################
  
Line 20: Line 20:
 
#
 
#
 
class Snippet1
 
class Snippet1
    include_package 'org.eclipse.swt.widgets'
+
include_package 'org.eclipse.swt.widgets'
   
+
    def Snippet1.main
+
def Snippet1.main
        display = Display.new
+
display = Display.new
        shell = Shell.new(display)
+
shell = Shell.new(display)
        shell.open
+
shell.open
  
        display.sleep unless display.readAndDispatch until shell.isDisposed
+
display.sleep unless display.readAndDispatch until shell.isDisposed
  
 
# the line above is the short form of:
 
# the line above is the short form of:
#       while !shell.isDisposed
+
# while !shell.isDisposed
#           if !display.readAndDispatch
+
# if !display.readAndDispatch
#               display.sleep
+
# display.sleep
#           end
+
# end
#       end  
+
# end  
  
        display.dispose
+
display.dispose
    end
+
end
 
end
 
end
  

Revision as of 08:23, 28 July 2009

################################################################################
# Copyright (c) 2009 IBM Corporation and others.
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
# http://www.eclipse.org/legal/epl-v10.html
#
# Contributors:
#	  IBM Corporation - initial API and implementation
################################################################################

require 'java'

# 
# example snippet: Hello World
#
# For a list of SWT example snippets ported to JRuby, see
# http://wiki.eclipse.org/JRuby/SWTSnippets
#
class Snippet1
	include_package 'org.eclipse.swt.widgets'
	
	def Snippet1.main
		display = Display.new
		shell = Shell.new(display)
		shell.open

		display.sleep unless display.readAndDispatch until shell.isDisposed

# the line above is the short form of:
#		while !shell.isDisposed
#			if !display.readAndDispatch
#				display.sleep
#			end
#		end 

		display.dispose
	end
end

Snippet1.main

Compare with the Java version.