Home Tutorials Jruby "Hello World" program in Swing and JRuby



"Hello World" program in Swing and JRuby
Posted on: September 29, 2008 at 12:00 AM
In the previous section of JRuby Tutorials you have studied how to use Java classes in JRuby examples to show results on your console.

"Hello World" program in Swing and JRuby

     

In the previous section of JRuby Tutorials you have studied how to use Java classes in JRuby examples to show results on your console. Now we are going to describe you how to use Swing in JRuby program. 

In this example we will create our first  "HelloWorld" swing application in  JRuby. First line in our program tells that we are making our JRuby program enabled to use java classes. 

frame = javax.swing.JFrame.new() creates a new variable object "frame" which is an instance of javax.swing.JFrame .

frame.getContentPane().add(javax.swing.JLabel.new("Hello World")) will add a new JLabel to this frame via getting the content pane.

frame.set_visible(true) makes frame to be visible. Here is the full example code of JRubySwingHello.rb as follows:

 

 

 

JRubySwingHello.rb

require "java"
frame = javax.swing.JFrame.new()
frame.getContentPane().add(javax.swing.JLabel.new("Hello World"))
frame.setDefaultCloseOperation(javax.swing.JFrame::EXIT_ON_CLOSE)
frame.pack()
frame.set_visible(true)

Output:

Type the following command in your command prompt to execute this example:

C:\JRuby>jruby JRubySwingHello.rb


Download Source Code

     

Related Tags for "Hello World" program in Swing and JRuby:
javacrubyswingclassconsoletutorialsioclassesexamplesjrubyvitutorialoleriashowieexampleprogramresultstoramexamsseshedessectionlsuseulresultinnoasmjcleshowprodescribetorxaxampssusohaltsmplpregoarconswingvatutorscrssrithshoswavstpleplpronogrolo


More Tutorials from this section

Ask Questions?    Discuss: "Hello World" program in Swing and JRuby  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.