JRuby: Java and Ruby Together at Last, Page 3
How About Swing in JRuby?
Swing is a GUI framework that allows developers to create graphical applications using the Java language. Here is a sample program, javaSwingHello.rb, which uses Java Swing to print a message:
require 'java' include_class "javax.swing.JFrame" include_class "javax.swing.JLabel" frame = JFrame.new() jlabel = JLabel.new("Hello from JRuby with Swing") frame.getContentPane().add(jlabel) # frame.content_pane.add(label) frame.pack() frame.setVisible(true) frame.visible = true
Run this from the command line as follows:
This article has provided a brief introduction to the JRuby language. JRuby should allow existing Java developers to leverage Ruby's power and ease of programming. Ruby developers will be exposed to the vast Java libraries that have made Java extensively used throughout the software development spectrum. With backing from Sun, JRuby looks to have a bright future. Take some time to look further into JRuby and see what all it has to offer you.
- Ruby: http://www.ruby-lang.org/en/
- Java: http://java.sun.com/
- Java Programming Language: http://en.wikipedia.org/wiki/Java_language
- JRuby: http://jruby.codehaus.org/
- Bringing Ruby to the JVM: http://www.infoq.com/presentations/JRuby
- Sun hires JRuby developers: http://www.tbray.org/ongoing/When/200x/2006/09/07/JRuby-guys
- Ruby on Rails: http://www.rubyonrails.org/
- Bean Scripting Framework (BSF): http://jakarta.apache.org/bsf/
- Java Swing: http://en.wikipedia.org/wiki/Swing_(Java)
- SilvaSoft, Inc. weblog: http://jroller.com/page/silvasoftinc
About the Author
Dominic Da Silva (http://www.dominicdasilva.com/) is the President of SilvaSoft, Inc., a software consulting company specializing Java-, Ruby-, and .NET-based web and web services development. He has worked with Java since 2000 and is a Linux user from the 1.0 days. He also is Sun Certified for the Java 2 platform. Born on the beautiful Caribbean island of Trinidad and Tobago, he now makes his home in sunny Orlando, Florida.
Page 3 of 3