如何使用 JRuby 创建 Java 小程序? [英] How do you create a Java applet using JRuby?

查看:30
本文介绍了如何使用 JRuby 创建 Java 小程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 JRuby 创建一个 Java 小程序.也就是说,我想用 JRuby 内部运行的 Ruby 代码创建一个 Java 小程序,以完成所有 GUI 工作.我正在寻找一个简单的示例来说明如何开始.

I want to create a Java applet using JRuby. That is, I want to create a Java applet with Ruby code inside run by JRuby to do all the GUI stuff. I am looking for a simple example of how to do this to get started.

推荐答案

查看这些链接...

来自我们代码库的 JRubyApplet:https://github.com/jruby/jruby/blob/master/src/org/jruby/JRubyApplet.java

JRubyApplet from our codebase: https://github.com/jruby/jruby/blob/master/src/org/jruby/JRubyApplet.java

用于构建签名小程序的 Rake 任务:https://github.com/jruby/jruby/blob/master/rakelib/applet.rake

Rake tasks for building a signed applet: https://github.com/jruby/jruby/blob/master/rakelib/applet.rake

jruby.org/tryjruby 页面的来源:https://github.com/jruby/jruby.github.com/blob/master/www/tryjruby.html

Source for jruby.org/tryjruby page: https://github.com/jruby/jruby.github.com/blob/master/www/tryjruby.html

对于您的情况,您可能拥有 Java 中的小程序,引导一个 org.jruby.embed.ScriptingContainer 实例,然后将 Applet 实例提供给它,以便它可以在 Ruby 脚本中添加您的 UI 元素.小程序 jar 中的任何内容都可以直接加载,例如require 'my_applet.rb' 将在 jar 中查找/my_applet.rb.

For your case, you'd probably have the applet in Java, bootstrap an org.jruby.embed.ScriptingContainer instance, and then feed it the Applet instance so it can add your UI elements in a Ruby script. Anything in the applet jar can be loaded directly, e.g. require 'my_applet.rb' will look for /my_applet.rb in the jar.

享受吧!

这篇关于如何使用 JRuby 创建 Java 小程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆