Author: rony Date: Thu Sep 7 00:55:55 2006 New Revision: 441009 URL: http://svn.apache.org/viewvc?view=rev&rev=441009 Log: 20060907 added ooRexx examples, added hint of language in title.
Added: jakarta/bsf/trunk/samples/bsh/calculator.rex (with props) jakarta/bsf/trunk/samples/bsh/download.rex (with props) Modified: jakarta/bsf/trunk/samples/bsh/calculator.jacl jakarta/bsf/trunk/samples/bsh/calculator.js jakarta/bsf/trunk/samples/bsh/calculator.py jakarta/bsf/trunk/samples/bsh/download.js Modified: jakarta/bsf/trunk/samples/bsh/calculator.jacl URL: http://svn.apache.org/viewvc/jakarta/bsf/trunk/samples/bsh/calculator.jacl?view=diff&rev=441009&r1=441008&r2=441009 ============================================================================== --- jakarta/bsf/trunk/samples/bsh/calculator.jacl (original) +++ jakarta/bsf/trunk/samples/bsh/calculator.jacl Thu Sep 7 00:55:55 2006 @@ -3,7 +3,7 @@ package require java -set f [java::new java.awt.Frame "BSH Calculator"] +set f [java::new java.awt.Frame "BSH Calculator (jacl/tcl)"] bsf addEventListener $f "window" "windowClosing" "exit" set p [java::new java.awt.Panel] @@ -43,9 +43,9 @@ proc getField {f} { set t [$f getText] - if {$t == ""} { + if {$t == ""} { return 0 - } else { + } else { return [java::call java.lang.Integer parseInt $t] } } Modified: jakarta/bsf/trunk/samples/bsh/calculator.js URL: http://svn.apache.org/viewvc/jakarta/bsf/trunk/samples/bsh/calculator.js?view=diff&rev=441009&r1=441008&r2=441009 ============================================================================== --- jakarta/bsf/trunk/samples/bsh/calculator.js (original) +++ jakarta/bsf/trunk/samples/bsh/calculator.js Thu Sep 7 00:55:55 2006 @@ -1,8 +1,8 @@ /* A silly little calculator implemented in Javascript (Rhino) using Java components for the UI. */ -f = new java.awt.Frame ("BSH Calculator"); -bsf.addEventListener (f, "window", "windowClosing", +f = new java.awt.Frame ("BSH Calculator (js)"); +bsf.addEventListener (f, "window", "windowClosing", "java.lang.System.exit (0);"); f1 = new java.awt.TextField (20); Modified: jakarta/bsf/trunk/samples/bsh/calculator.py URL: http://svn.apache.org/viewvc/jakarta/bsf/trunk/samples/bsh/calculator.py?view=diff&rev=441009&r1=441008&r2=441009 ============================================================================== --- jakarta/bsf/trunk/samples/bsh/calculator.py (original) +++ jakarta/bsf/trunk/samples/bsh/calculator.py Thu Sep 7 00:55:55 2006 @@ -23,7 +23,7 @@ prod.setText (repr (n1 * n2)) quo.setText (repr (n1 / n2)) -f = awt.Frame ('BSH Calculator', windowClosing=exit) +f = awt.Frame ('BSH Calculator (jpython)', windowClosing=exit) f1 = awt.TextField (20, actionPerformed=doMath) f2 = awt.TextField (20, textValueChanged=doMath) Added: jakarta/bsf/trunk/samples/bsh/calculator.rex URL: http://svn.apache.org/viewvc/jakarta/bsf/trunk/samples/bsh/calculator.rex?view=auto&rev=441009 ============================================================================== --- jakarta/bsf/trunk/samples/bsh/calculator.rex (added) +++ jakarta/bsf/trunk/samples/bsh/calculator.rex Thu Sep 7 00:55:55 2006 @@ -0,0 +1,83 @@ +/* A silly little calculator implemented in Object Rexx using + Java components for the UI. 2001-05-02, 2003-01-23, ---rgf, 2003-05-10 + ("bsf\samples\bsh\calculator.js" served as an example) + + license: + + ------------------------ Apache Version 2.0 license ------------------------- + Copyright (C) 2001-2006 Rony G. Flatscher + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ----------------------------------------------------------------------------- +*/ + +if BsfInvokedBy()=1 then say "This Rexx program was invoked by Java!" +else if BsfInvokedBy()=2 then say "This Rexx program was invoked by Rexx, JVM loaded by Rexx!" +else say "No JVM present, we got troubles ..." + +.bsf~bsf.import("java.awt.TextField", "awtTextField") +.bsf~bsf.import("java.awt.Label" , "awtLabel" ) + +f = .bsf~new("java.awt.Frame", "BSH Calculator (ooRexx)") +f~bsf.addEventListener("window", "windowClosing", "call bsf 'exit'") + +f1 = .awtTextField~newStrict("int", 20) -- "newStrict" to force the constructor with the "int" argument +f1~bsf.addEventListener("action", "", "call doMath /* action event */") + +f2 = .awtTextField~newStrict("int", 20) +f2~bsf.addEventListener("text", "", "call doMath /* text event */") + +p = .bsf~new( "java.awt.Panel") ~~setLayout(.bsf~new("java.awt.GridLayout", 2, 2)) +p ~~add(.awtLabel~new("Enter operand")) ~~add(f1) +p ~~add(.awtLabel~new("Enter operand")) ~~add(f2) + +f ~~add("North", p) ~~add("Center", .awtLabel~new("Results:")) + +p = .bsf~new("java.awt.Panel") ~~setLayout(.bsf~new("java.awt.GridLayout", 4, 2)) + +sum= .awtTextField~newStrict("int", 20) +p ~~add(.awtLabel~new("Sum")) ~~add(sum) + +diff= .awtTextField~newStrict("int", 20) +p ~~add(.awtLabel~new("Difference")) ~~add(diff) + +prod= .awtTextField~newStrict("int", 20) +p ~~add(.awtLabel~new("Product")) ~~add(prod) + +quo = .awtTextField~newStrict("int", 20) +p ~~add(.awtLabel~new("Quotient")) ~~add(quo) + +f ~~add("South", p) ~~pack ~~show ~~toFront + +do forever + interpret .bsf~bsf.pollEventText -- retrieve eventText and interpret it +end +exit + +getField: procedure + use arg f + t=f~getText + if t="" then return 0 + return t + +doMath: + n1 = getField(f1); if n1="-" then n1=-1;else if n1="+" then n1=1 + n2 = getField(f2); if n2="-" then n2=-1;else if n2="+" then n2=1 + sum ~setText(n1+n2) + diff~setText(n1-n2) + prod~setText(n1*n2) + if n2=0 then quo~setText("DIVISION by 0 !!!") + else quo~setText(n1/n2) + return + +::requires BSF.CLS -- get Object Rexx wrapper support Propchange: jakarta/bsf/trunk/samples/bsh/calculator.rex ------------------------------------------------------------------------------ svn:eol-style = native Propchange: jakarta/bsf/trunk/samples/bsh/calculator.rex ------------------------------------------------------------------------------ svn:executable = * Propchange: jakarta/bsf/trunk/samples/bsh/calculator.rex ------------------------------------------------------------------------------ svn:keywords = Author Date Rev Id URL Modified: jakarta/bsf/trunk/samples/bsh/download.js URL: http://svn.apache.org/viewvc/jakarta/bsf/trunk/samples/bsh/download.js?view=diff&rev=441009&r1=441008&r2=441009 ============================================================================== --- jakarta/bsf/trunk/samples/bsh/download.js (original) +++ jakarta/bsf/trunk/samples/bsh/download.js Thu Sep 7 00:55:55 2006 @@ -1,5 +1,6 @@ /* This is a simple demo of a JavaScript script that uses the Java - URL class to download some content from some URL. */ + URL class to download some content from some URL. + */ URL_ADDR = "http://www.cnn.com/"; Added: jakarta/bsf/trunk/samples/bsh/download.rex URL: http://svn.apache.org/viewvc/jakarta/bsf/trunk/samples/bsh/download.rex?view=auto&rev=441009 ============================================================================== --- jakarta/bsf/trunk/samples/bsh/download.rex (added) +++ jakarta/bsf/trunk/samples/bsh/download.rex Thu Sep 7 00:55:55 2006 @@ -0,0 +1,39 @@ +/* This is a simple demo of a Rexx (modelled after the JavaScript) script that + uses the Java URL class to download some content from some URL. rgf, 2003-01-27, 2003-05-10 + + license: + + ------------------------ Apache Version 2.0 license ------------------------- + Copyright (C) 2003-2006 Rony G. Flatscher + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ----------------------------------------------------------------------------- +*/ + + /* use the Java URL class to read data from a WWW server */ +URL_ADDR = "http://www.RexxLA.org/"; + +say "connecting to:" URL_ADDR +url=.bsf~new("java.net.URL", URL_ADDR) -- create a URL instance + + /* get the content, a <sun.net.www.http.KeepAliveStream> a subclass of: <sun.net.www.MeteredStream>, a subclass of: <java.io.FilterInputStream> */ +content = url~getContent /* get the content object */ +say "Bytes available:" content~available /* get # of bytes */ +say "Downloading .. " +ch="" +do until ch=-1 /* read the content */ + ch=content~read /* returns an Integer value representing a Byte or -1 */ + if ch>=0 then call charout , ch~d2c /* turn Byte integer value into character */ +end + +::requires BSF.CLS -- Object Rexx wrapper classes Propchange: jakarta/bsf/trunk/samples/bsh/download.rex ------------------------------------------------------------------------------ svn:eol-style = native Propchange: jakarta/bsf/trunk/samples/bsh/download.rex ------------------------------------------------------------------------------ svn:executable = * Propchange: jakarta/bsf/trunk/samples/bsh/download.rex ------------------------------------------------------------------------------ svn:keywords = Author Date Rev Id URL --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]