More Tutorials| Bioinformatics| Open Source| Photoshop| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
"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.

 

"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

                         

» View all related tutorials
Related Tags: c ruby ide class ant variables scope classes variable sed const constants jruby name using instance ria this id tar

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.