Created
August 29, 2011 01:14
-
-
Save IndianGuru/1177514 to your computer and use it in GitHub Desktop.
JRuby programs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
public class InternationalizationEx | |
{ | |
public static void main(String[] args) | |
{ | |
String lang, country; | |
Locale cLocale; | |
ResourceBundle msg; | |
lang = new String("de"); | |
country = new String("DE"); | |
cLocale = new Locale(lang, country); | |
msg = ResourceBundle.getBundle("MessagesBundle", cLocale); | |
System.out.println(msg.getString("greetings")); | |
System.out.println(msg.getString("welcome")); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'java' | |
java_import java.lang.System | |
puts System.get_property("os.name") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'java' | |
java_import 'java.lang.String' do |package,name| | |
"J#{name}" | |
end | |
ResourceBundle = java.util.ResourceBundle | |
Locale = java.util.Locale | |
lang = JString.new 'de' | |
country = JString.new 'DE' | |
cLocale = Locale.new lang, country | |
msg = ResourceBundle.get_bundle 'MessagesBundle', cLocale | |
puts msg.get_string 'greetings' | |
puts msg.get_string 'welcome' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'java' | |
java_import('java.lang.String') do |package,name| | |
"J#{name}" | |
end | |
ResourceBundle = java.util.ResourceBundle | |
Locale = java.util.Locale | |
lang = JString.new 'pt' | |
country = JString.new 'BR' | |
cLocale = Locale.new lang, country | |
msg = ResourceBundle.get_bundle 'MessagesBundle', cLocale | |
puts msg.get_string 'greetings' | |
puts msg.get_string 'welcome' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'java' | |
JFrame = javax.swing.JFrame | |
JLabel = javax.swing.JLabel | |
frame = JFrame.new | |
jlabel = JLabel.new 'Hello World' | |
frame.add jlabel | |
frame.set_default_close_operation JFrame::EXIT_ON_CLOSE | |
frame.pack | |
frame.set_size 200, 200 | |
frame.set_visible true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Extending a Java class | |
class MyButtons < Java::java.awt.Frame | |
def initialize(title) | |
super(title) | |
button = Java::java.awt.Button.new('OK') | |
panel = Java::java.awt.Panel.new | |
panel.add(button) | |
button.add_action_listener ClickAction.new | |
add(panel, Java::java.awt.BorderLayout::SOUTH) | |
set_visible(true) | |
end | |
end | |
class ClickAction | |
# Implementing a Java interface | |
include Java::java.awt.event.ActionListener | |
def actionPerformed(e) | |
puts 'Button is Pressed' | |
end | |
end | |
mb = MyButtons.new('Sample Swing app') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment