Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
Difference between revisions of "JRuby/SWTSnippets/Snippet1.rb"
< JRuby | SWTSnippets
(5 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
<pre> | <pre> | ||
+ | ################################################################################ | ||
+ | # 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' | require 'java' | ||
# | # | ||
# example snippet: Hello World | # example snippet: Hello World | ||
+ | # | ||
+ | # For a list of SWT example snippets ported to JRuby, see | ||
+ | # http://wiki.eclipse.org/JRuby/SWTSnippets | ||
# | # | ||
class Snippet1 | 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 spins the event loop; it's the short form of: | |
− | + | # while !shell.isDisposed | |
− | + | # if !display.readAndDispatch | |
− | + | # display.sleep | |
− | + | # end | |
+ | # end | ||
+ | |||
+ | display.dispose | ||
+ | end | ||
end | end | ||
Snippet1.main | Snippet1.main | ||
− | |||
</pre> | </pre> | ||
+ | |||
+ | Compare with the [http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet1.java Java version]. |
Latest revision as of 08:24, 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 spins the event loop; it's 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.