Skip to content

Instantly share code, notes, and snippets.

@IndianGuru
Created August 29, 2011 01:14
Show Gist options
  • Save IndianGuru/1177514 to your computer and use it in GitHub Desktop.
Save IndianGuru/1177514 to your computer and use it in GitHub Desktop.
JRuby programs
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"));
}
}
require 'java'
java_import java.lang.System
puts System.get_property("os.name")
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'
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'
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
# 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