这是一个支持动态类型的脚本语言,支持函数式编程和prototype based面向对象的OO开发。这个语言同Java可以无缝衔接:可以容易的访问Java的类,同时可以被Java的代码调用。
同Python、Ruby和Groovy相比,这个语言的语法相对更接近Java。所以熟悉Java的朋友学习起来很容易。
这个动态类型的脚本语言可以极大地加快你的开发速度,让你可以轻松完成开发任务。
如果你感兴趣,可以到这个网站查看详细信息: http://www.stonezhong.net/orangescript/index.html
下面是一个用Swing类库的计算器程序的示范程序。
运行方法:
(1) 你必须有JRE 1.6或者1.7已经安装
(2) 下载OrangeScript.jar
wget http://www.stonezhong.net/orangescript/OrangeScript.jar
(3) 下载计算器源码
wget http://www.stonezhong.net/orangescript/contents/examples/calculator.os
(4) 运行
java -classpath OrangeScript.jar orangeScript.parser.Main -file calculator.os
计算器源码
/**
* Simple Calculator.
* This example shows Orange Script can do Java GUI programming.
*
* Author: Stone Zhong, stonezhong@hotmail.com
* Date : Dec 12, 2013
*/
var EventQueue = $.java.awt.EventQueue;
var ORunnable = $.orangeScript.javahelper.ORunnable;
var JFrame = $.javax.swing.JFrame;
var JPanel = $.javax.swing.JPanel;
var JButton = $.javax.swing.JButton;
var GridLayout = $.java.awt.GridLayout;
var BorderLayout = $.java.awt.BorderLayout;
var OActionListener = $.orangeScript.javahelper.OActionListener;
var String = $.java.lang.String;
var Double = $.java.lang.Double;
EventQueue.invokeLater(ORunnable.new(function() {
var frame = JFrame.new();
frame.setSize(300, 200);
frame.setTitle("Calculator");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
var panel = JPanel.new();
panel.setLayout(BorderLayout.new());
frame.add(panel);
var display = JButton.new("0");
display.setEnabled(false);
panel.add(BorderLayout.NORTH, display);
var panel2 = JPanel.new();
panel2.setLayout(GridLayout.new(4, 4));
panel.add(BorderLayout.CENTER, panel2);
var start = true;
var lastCmd = "=";
var result = 0;
var insert = function(event) {
if (start) {
display.setText("");
start = false;
}
var input = event.getActionCommand();
display.setText(display.getText() + input);
};
var command = function(event) {
var input = event.getActionCommand();
if (start) {
if (input == "-") {
display.setText("-");
start = false;
} else lastCmd = input;
} else {
calculate(Double.parseDouble(display.getText()));
lastCmd = input;
start = true;
}
};
var calculate = function(x) {
if (lastCmd == "+")
result = result + x;
else if (lastCmd == "-")
result = result - x;
else if (lastCmd == "*")
result = result * x;
else if (lastCmd == "/")
result = result / x;
else if (lastCmd == "=")
result = x;
display.setText(String.valueOf(result));
};
var addButton = function(message, handler) {
var btn = JButton.new(message);
panel2.add(btn);
btn.addActionListener(OActionListener.new(handler));
};
addButton("7", insert);
addButton("8", insert);
addButton("9", insert);
addButton("/", command);
addButton("4", insert);
addButton("5", insert);
addButton("6", insert);
addButton("*", command);
addButton("1", insert);
addButton("2", insert);
addButton("3", insert);
addButton("-", command);
addButton("0", insert);
addButton(".", insert);
addButton("=", command);
addButton("+", command);
}));
5 个解决方案
#1
没搞懂是什么语言
#2
OrangeScript......
#3
jython不是就可以调用java的类,还用的是python的语法吗?
#4
fun main(args : Array<String>) {
if (args.size == 0) {
println("Please provide a name as a command-line argument")
return
}
println("Hello, ${args[0]}!")
}
http://kotlin.jetbrains.org/
if (args.size == 0) {
println("Please provide a name as a command-line argument")
return
}
println("Hello, ${args[0]}!")
}
http://kotlin.jetbrains.org/
#5
楼主的英文有待提高!建议重新打磨一下文档!
Variable s must be declared before it can be referenced, reference a undeclared variable is a runtime error.
例如这一句。
Variable s must be declared before it can be referenced, reference a undeclared variable is a runtime error.
例如这一句。
#1
没搞懂是什么语言
#2
OrangeScript......
#3
jython不是就可以调用java的类,还用的是python的语法吗?
#4
fun main(args : Array<String>) {
if (args.size == 0) {
println("Please provide a name as a command-line argument")
return
}
println("Hello, ${args[0]}!")
}
http://kotlin.jetbrains.org/
if (args.size == 0) {
println("Please provide a name as a command-line argument")
return
}
println("Hello, ${args[0]}!")
}
http://kotlin.jetbrains.org/
#5
楼主的英文有待提高!建议重新打磨一下文档!
Variable s must be declared before it can be referenced, reference a undeclared variable is a runtime error.
例如这一句。
Variable s must be declared before it can be referenced, reference a undeclared variable is a runtime error.
例如这一句。