Permalink
Browse files

Follow up to JRUBY-168: Change our samples to use new syntax

git-svn-id: http://svn.codehaus.org/jruby/trunk/jruby@2278 961051c9-f516-0410-bf72-c9f7e237a7b7
  • Loading branch information...
1 parent ee94722 commit a5329c86727d984e74408e39e361a3f039c6f014 @enebo enebo committed Oct 4, 2006
Showing with 21 additions and 36 deletions.
  1. +2 −5 samples/error.rb
  2. +2 −6 samples/java2.rb
  3. +5 −8 samples/swing.rb
  4. +4 −6 samples/swing2.rb
  5. +8 −11 samples/xslt.rb
View
@@ -3,11 +3,8 @@
Java::define_exception_handler "java.lang.NumberFormatException" do |e|
puts e.java_type
+ p e.methods
puts e.java_class.java_method(:getMessage).invoke(e)
end
-module JavaLang
- include_package 'java.lang'
-end
-
-JavaLang::Long.parseLong("23aa")
+java.lang.Long.parseLong("23aa")
View
@@ -1,12 +1,8 @@
require "java"
-include_class "java.io.FileReader"
-include_class "java.io.BufferedReader"
-
filename = "./samples/java2.rb"
-
-fr = FileReader.new filename
-br = BufferedReader.new fr
+fr = java.io.FileReader.new filename
+br = java.io.BufferedReader.new fr
s = br.readLine
View
@@ -1,12 +1,9 @@
require 'java'
-include_class "javax.swing.JFrame"
-include_class "javax.swing.JLabel"
+JFrame = javax.swing.JFrame
frame = JFrame.new("Hello Swing")
-label = JLabel.new("Hello World")
-
-frame.getContentPane().add(label)
-frame.setDefaultCloseOperation(JFrame::EXIT_ON_CLOSE)
-frame.pack()
-frame.setVisible(true)
+frame.getContentPane.add javax.swing.JLabel.new("Hello World")
+frame.setDefaultCloseOperation JFrame::EXIT_ON_CLOSE
+frame.pack
+frame.setVisible true
View
@@ -1,16 +1,14 @@
-
# Import Java packages
require 'java'
-include_class "java.awt.event.ActionListener"
-include_class ["JButton", "JFrame", "JLabel", "JOptionPane"].map {|e| "javax.swing." + e}
+JFrame = javax.swing.JFrame
frame = JFrame.new("Hello Swing")
-button = JButton.new("Klick Me!")
+button = javax.swing.JButton.new("Klick Me!")
-class ClickAction < ActionListener
+class ClickAction < java.awt.event.ActionListener
def actionPerformed(evt)
- JOptionPane.showMessageDialog(nil, "<html>Hello from <b><u>JRuby</u></b>.<br> Button '#{evt.getActionCommand()}' clicked.")
+ javax.swing.JOptionPane.showMessageDialog(nil, "<html>Hello from <b><u>JRuby</u></b>.<br> Button '#{evt.getActionCommand()}' clicked.")
end
end
button.addActionListener(ClickAction.new)
View
@@ -2,11 +2,8 @@
require 'optparse'
require 'ostruct'
-include_class "java.lang.System"
-include_class("java.lang.Exception") {|p,n| "J" + n }
-include_class "java.io.FileOutputStream"
-include_class "javax.xml.transform.TransformerFactory"
-include_class ["StreamSource", "StreamResult"].map {|e| "javax.xml.transform.stream." + e}
+FileOutputStream = java.io.FileOutputStream
+StreamSource = javax.xml.transform.stream.StreamSource
class XSLTOptions
def self.parse(args)
@@ -38,15 +35,15 @@ def self.parse(args)
exit
end
-document = StreamSource.new(ARGV[0])
-stylesheet = StreamSource.new(ARGV[1])
-output = ARGV.length == 2 ? System::out : FileOutputStream.new(ARGV[2])
-result = StreamResult.new(output)
+document = StreamSource.new ARGV[0]
+stylesheet = StreamSource.new ARGV[1]
+output = ARGV.length == 2 ? java.lang.System::out : FileOutputStream.new(ARGV[2])
+result = javax.xml.transform.stream.StreamResult.new output
begin
- transformer = TransformerFactory.newInstance.newTransformer(stylesheet)
+ transformer = javax.xml.transform.TransformerFactory.newInstance.newTransformer(stylesheet)
options.parameters.each {|name, value| transformer.setParameter name, value }
transformer.transform(document, result)
-rescue Exception => e
+rescue java.lang.Exception => e
puts e
end

0 comments on commit a5329c8

Please sign in to comment.