Author: rony Date: Thu Sep 7 01:03:35 2006 New Revision: 441012 URL: http://svn.apache.org/viewvc?view=rev&rev=441012 Log: 20060907 added 'TestCalc.rex' which works on all platforms; the original Windows-script examples do not work on the present version, due to the missing OLE/ActiveX infrastructure (cf. 'readme').
Added: jakarta/bsf/trunk/samples/calc/TestCalc.rex (with props) Modified: jakarta/bsf/trunk/samples/calc/readme Added: jakarta/bsf/trunk/samples/calc/TestCalc.rex URL: http://svn.apache.org/viewvc/jakarta/bsf/trunk/samples/calc/TestCalc.rex?view=auto&rev=441012 ============================================================================== --- jakarta/bsf/trunk/samples/calc/TestCalc.rex (added) +++ jakarta/bsf/trunk/samples/calc/TestCalc.rex Thu Sep 7 01:03:35 2006 @@ -0,0 +1,130 @@ +/* to be placed in "samples/calc/TestCalc-oo.rxj"; Object Rexx version + +add the following line to "samples/calc/TestCalc.java" in +the static method where the extensionmap is defined: + + extensionmap.put("rex", "rexx"); + extensionmap.put("rxj", "rexx"); + +---rgf, 2001-05-02 (on the way back home from the 12th Int'l Rexx Symposium +---rgf, 2003-01-23 (on the way back home from Augsburg by train), ---rgf, 2003-05-10 + + ------------------------ 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 rxFuncQuery("BSF") then /* no bsf4rexx support available yet, hence load Java */ +do + call rxFuncAdd "BsfLoadFuncs", "BSF4Rexx", "BsfLoadFuncs" + call BsfLoadFuncs /* load all BSF-functions */ + call BsfLoadJava /* load the JVM and set up BSF4Rexx-support */ +end + +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 ..." + + +/********************************************************* + * A simple four function calculator, written in REXX * + *********************************************************/ + +/* *** create a res window */ +res = .bsf~new("java.awt.TextField", 0) + + +/* *** create a panel of buttons */ +panel = .bsf~new("java.awt.Panel") +panel~setLayout(.bsf~new("java.awt.GridLayout", 4, 4)) + +buttons = "789*456/123-C0.+" +do i=1 to buttons~length + label=buttons~substr(i, 1) + button=.bsf~new("java.awt.Button", label) + panel~add(button) + + if "*/-+"~pos(label)>0 then + button~bsf.addEventListener("action", "", "call op '" ||label||"'") + + else if label="C" then + button~bsf.addEventListener("action", "", "call clear") + + else + button~bsf.addEventListener("action", "", "call press" label) +end + + +/* *** Place everything in the frame */ +frame = .bsf~bsf.lookupBean("frame") +frame~~setTitle("Object Rexx Calc") ~~resize(130, 200) +frame~~add("North", res) ~~add("Center", panel) +frame~~validate ~~show +frame~bsf.addEventListener("window", "windowClosing", "call bsf 'exit'") + +/* *** Initialize the state of the calculator */ +mem = 0 +nextOp = "+" +autoClear = 1 /* true */ + +do forever /* get eventText and execute it as a Rexx program */ + interpret .bsf~bsf.pollEventText +end +exit + + +press: /* handle data entry keys */ + parse arg key + + if autoClear then + res~bsf.invokestrict("setText", "str", 0) + + if res~getText=="0" & key<>"." then + res~bsf.invokeStrict("setText", "str", "") + -- res~setText("str", "") + + if key="." then + if pos(".", res~getText)>0 then + key="" + + -- res~setText("str", res~getText || key) + res~bsf.invokeStrict("setText", "str", res~getText || key) + + autoClear=0 /* set it to false */ + return + +/* *** handle arithmetic keys */ +op: + parse arg key + num=res~getText + if nextOp="+" then mem=mem+num + else if nextOp="-" then mem=mem-num + else if nextOp="*" then mem=mem*num + else if nextOp="/" & num<>0 then mem=mem/num + nextOp=key + -- res~setText("str", mem) + res~bsf.invokeStrict("setText", "str", mem) + autoClear=1 /* set to true */ + return + +/* handle the "C" key */ +clear: + mem=0 + nextOp="" + -- res~setText("str", 0) + res~bsf.invokeStrict("setText", "str", 0) + return + +::requires BSF.CLS -- add Object Rexx proxy support Propchange: jakarta/bsf/trunk/samples/calc/TestCalc.rex ------------------------------------------------------------------------------ svn:eol-style = native Propchange: jakarta/bsf/trunk/samples/calc/TestCalc.rex ------------------------------------------------------------------------------ svn:executable = * Propchange: jakarta/bsf/trunk/samples/calc/TestCalc.rex ------------------------------------------------------------------------------ svn:keywords = Author Date Rev Id URL Modified: jakarta/bsf/trunk/samples/calc/readme URL: http://svn.apache.org/viewvc/jakarta/bsf/trunk/samples/calc/readme?view=diff&rev=441012&r1=441011&r2=441012 ============================================================================== --- jakarta/bsf/trunk/samples/calc/readme (original) +++ jakarta/bsf/trunk/samples/calc/readme Thu Sep 7 01:03:35 2006 @@ -1,3 +1,21 @@ +To run this demo type: + + java TestCalc filename + +Please note that as of 2006-09-07 the proprietary Windows scripting languages +do not run with the standard distribution. Reason: due to licensing issues IBM +was not able to donate the necessary supporting OLE/ActiveX C++ code. + +Maybe someone picks up this task? + +The Rexx example (transcribed from the original Windows script examples) works, +as it is not dependent on the Windows infrastructure: + + java TestCalc TestCalc.rex + +---rgf, 2006-09-07 + +================ original text of "readme" as of 2003-10-07 ============= To run this demo type: java TestCalc filename --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]