dcsimg
October 23, 2018
Hot Topics:

JRuby: Java and Ruby Together at Last

  • October 26, 2006
  • By Dominic Da Silva
  • Send Email »
  • More Articles »

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:

C:\JRuby>jruby javaSwingHello.rb

A new window will appear with the text "Hello from JRuby with Swing":

Conclusion

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.

References

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



Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

By submitting your information, you agree that developer.com may send you developer offers via email, phone and text message, as well as email offers about other products and services that developer believes may be of interest to you. developer will process your information in accordance with the Quinstreet Privacy Policy.

Sitemap

Thanks for your registration, follow us on our social networks to keep up-to-date