# To change this template, choose Tools | Templates
# and open the template in the editor.
#puts "Hello World"
include Java
include_class javax.swing.JFrame
include_class javax.swing.JPanel
include_class javax.swing.JButton
include_class java.awt.event.ActionListener
include_class javax.swing.JOptionPane
#include_class java.awt.Container
class ButtonFrame < JFrame
def initialize
super "Hello world Swing"
setTitle__method "Button"
set_size(300,200)
panel=ButtonPanel.new
getContentPane().add(panel)
set_default_close_operation JFrame::EXIT_ON_CLOSE
set_visible true
end
end
class ButtonPanel <JPanel
def initialize
super
yellowbutton=JButton.new("Yellow")
redbutton=JButton.new("Red")
bluebutton=JButton.new("Blue")
add(yellowbutton)
add(redbutton)
add(bluebutton)
yellowbutton.addActionListener(Color_T.new("yellow"))
bluebutton.addActionListener(Color_T.new("blue"))
redbutton.addActionListener(Color_T.new("red"))
end
class Color_T
include ActionListener
def initialize(c)
@c=c
end
def action_performed(event)
JOptionPane.show_message_dialog(nil,"#{@c}")
end
end
end
ButtonFrame.new
很简单的一个小应用。通过这个小例子可以看出JRuby调用Java中的东西很方便。不过我的代码写得有点臃肿,这里主要是想明白调用的过程。
我对Java一直有点恐惧,Java要了解的东西太多了,特别是由于刚开始接触的时候,受到一定的打击,现在仍然有点惧,感觉有很多东西很深奥。但是实际上,并非如此,其实原理还是很简单的,比如这里的监听这个东西,以前很害怕这个,弄不懂。
当接触到了Ruby之后呢,对语言稍微有点理解了,也消除了恐惧的心理,敢去正视它了
然后又出现了JRuby,使得Java和Ruby更好的结合,这个结合的过程同时也是个创新的过程。
现在我感觉,通过2种语言的对比学习,可以更好的理解2种语言。
分享到:
相关推荐
jruby是一个ruby的解析器,可将ruby解析为java文件,jruby作为ruby解析器时刻调用java代码
jruby安装包 和 jruby的lib库 JRuby是面向Ruby、基于Java虚拟机(JVM)的一种解释程序,它结合了Ruby语言的简易性和功能强大的JVM的执行机制,包括与Java库 全面集成。Rails彻底加快及简化了Web应用的开发,不过它让...
jruby-src-1.0.zip
jruby-1.3.1.jar包 解决org.jruby.exceptions.JumpException 等报错
本文介绍了JRuby的安装与配置。JRuby的安装需要JRuby以及JDK,本文使用的版本分别是JRuby 1.1.2以及Java 1.6。至于JRuby配置,文章主要介绍了测试JRuby安装的方法。
org.jruby.rar
jruby-complete-1.7.19.jar,java版本的ruby解析器
jruby-bin-1.3.1.zip 用于jruby语言研发的必要工具
JRuby window X64 开发软件
This book introduces you to three JRuby deployment strategies that give you the performance and scalability you need, while you use a language designed for rapid development. Explore common ...
jRuby On Rails WEB 2.0
JRuby语言实战技术,java下运用ruby
jruby 1.9.6 win64
JRuby在Java测试中的应用,使用脚本语言,高效快进行Java程序测试。
jruby-1.5.5+OperaWatir+RSpec
jruby与java使用开发,听说jruby能是swing的调用变为更简单
对于Jruby、Jython和Groovy三种动态语言,长期以来很多人犹豫于如何选择它们。本文提出一个非常有力的例证证明:如果你是一个基于Java虚拟机的开发者,那么请放弃Jruby和Jython。
Now you can bring the best of Ruby into the world of Java, with Using JRuby. Come to the source for the JRuby core team’s insights and insider tips. You’ll learn how to call Java objects seamlessly ...
Ruby 、 Rails 、JRuby 都是令人兴奋的技术
jruby-stdlib-1.7.23.jar