您的位置: 新闻频道 Ruby新闻

原创新闻 Cheri: 用JRuby创建Swing Builder应用的框架

2008-07-07 by 副主编 QQbyte
评论(3) 有622人浏览 cheri jruby swing
Cheri提供了用JRuby创建Swing Builder应用的框架,采用特定域语言(DSL),使得只需要非常简单的代码就创建优秀的Swing应用。



推荐下载超酷视频:(46.3 MB)总共: 17分钟15秒
http://media.screencastic.com/public/video_assets/1/01-cheri.mov

Cheri主页:http://cheri.rubyforge.org/

下面是简单的例子:

Cheri::Swing hello world

require 'rubygems'
require 'cheri/swing'
include Cheri::Swing

f = swing.frame('Hello World') { label 'Hello!' }
f.pack
f.visible = true





Cheri::Swing and Cheri::Html

require 'cheri/swing'
require 'cheri/html'
include Cheri::Swing
include Cheri::Html

folks = {
  "Susan" =>"Wife", "Larry" =>"Son",
  "Bob" => "Friend","MaryAnne" => "Friend",
}
@frame = swing.frame('Swing and Html') { |frm|
  size 240,180; box_layout frm,:Y_AXIS
  content_pane { background :WHITE }
  default_close_operation :EXIT_ON_CLOSE
  menu_bar { 
    menu('File') {  mnemonic :VK_F
      menu_item('Exit') { mnemonic :VK_X
        on_click { @frame.dispose }
  }}}
  scroll_pane {
    align :LEFT
    editor_pane {
      content_type 'text/html'
      editable false
      background color(255,255,240)
      html {head {
         style "body { font-family: sans-serif; }" }
        body {div(:align=>:center) {
        table(:width=>'90%',:border=>1) {
          tr th('Name'), th('Relationship'),
            :bgcolor=>:yellow
          folks.each do |name,rel|
            tr(:bgcolor=>'#e0ffff') {
              td {name}; td {rel} }
          end      
   }}}}}}
}
@frame.visible = true





来自:cheri.rubyforge.org

评论 共 3 条 发表评论

rubynroll 2008-07-08 16:17 引用
引用
我想知道这么做有意义吗

ruby优雅灵活的语法对于GUI开发有非凡的意义,然而创建符合Ruby Way的GUI binding并非容易。我用过RubyGenome2,感觉非常好,不知道这个RubySwing作得如何...
zsbfree 2008-07-08 11:33 引用
我想知道这么做有意义吗
xiuxiuxiu 2008-07-07 22:48 引用
编译出来是一样的class么?
不知道具体的应用环境是什么?

发表评论

您还没有登录,请登录后发表评论