Beispiel 1 If arg(1)='?' Then Do Parse Source source Say source Say 'Create a resizable window with a button that can be pressed to close the window' Exit 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 ..." -- Create a Java RexxProxy for controlling the closing of the application rexxCloseEH =.RexxCloseAppEventHandler~new -- Rexx event handler -- Create Java RexxProxy for the Rexx event handler rpCloseEH=BsfCreateRexxProxy(rexxCloseEH, , "java.awt.event.ActionListener", - "java.awt.event.WindowListener" ) /* create a Java awt window and a Java awt button */ tmpWin = .awtFrame~new('Hello World!') tmpWin~addWindowListener(rpCloseEH) tmpBut = .bsf~new("java.awt.Button", 'Alarm !') tmpBut~addActionListener(rpCloseEH) /* prepare window and show it, using cascading messages (two twiddles '~') */ tmpWin ~~add(tmpBut) ~~pack ~~setVisible(.true) ~~toFront rexxCloseEH~waitForExit -- wait until we are allowed to end the program -- if Java was loaded by Rexx, then terminate Java's RexxEngine to inhibit callbacks from Java call BSF.terminateRexxEngine ::REQUIRES BSF.CLS -- get the Java support /* one way, how to define a Java class in Object Rexx */ ::CLASS "awtFrame" SUBCLASS bsf ::METHOD init self~init:super('java.awt.Frame', ARG(1, 'A')) /* ------------------------------------------------------------------------ */ /* Rexx event handler to set "close app" indicator */ ::class RexxCloseAppEventHandler ::method init /* constructor */ expose closeApp closeApp = .false -- if set to .true, then it is safe to close the app ::attribute closeApp -- indicates whether app should be closed ::method unknown -- intercept unhandled events, do nothing ::method actionPerformed -- event method (from ActionListener) expose closeApp closeApp=.true -- indicate that the app should close ::method windowClosing -- event method (from WindowListener) expose closeApp closeApp=.true -- indicate that the app should close ::method waitForExit -- method blocks until attribute is set to .true expose closeApp guard on when closeApp=.true ....................................................................................................................................................... Beispiel 2 If arg(1)='?' Then Do Parse Source source Say source Say 'Create a resizable window showing its size (width and height) in the middle' Say 'After a short time this window is automatically downsized and then' Say 'enlarged a couple of times and the actual size is displayed each time.' Say 'Thereafter you can resize the window yourself and display the actual size' Say 'by pressing the respective button.' Exit 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 ..." -- Create a userData directory userData=.directory~new -- a directory which will be passed to Rexx with the event -- Create a framed window window = .bsf~new("java.awt.Frame", "Wie gross?") userData~window=window -- save window object for later use in event handler -- Create a Java RexxProxy for controlling the closing of the application rexxCloseEH =.RexxCloseAppEventHandler~new -- Rexx event handler -- Create Java RexxProxy for the Rexx event handler rpCloseEH=BsfCreateRexxProxy(rexxCloseEH, , "java.awt.event.WindowListener" ) window~addWindowListener(rpCloseEH) -- add RexxProxy event handler -- Create a button button = .bsf~new("java.awt.Button", 'Was so gross?!') -- Create a RexxProxy for the button Rexx event handler rp=BsfCreateRexxProxy(.RexxShowSizeEventHandler~new, userData, "java.awt.event.ActionListener") button~addActionListener(rp) -- add RexxProxy event handler -- Create a label label = .bsf~new("java.awt.Label") userData~label=label -- save label object for later use in event handler label~setAlignment(label~CENTER) -- add label and button to framed window, pack it window ~~add("Center", label) ~~add("South", button) ~~pack -- set initial size and location, make frame visible and put it to front window ~~setSize(500, 300) ~~setLocation(150, 150) ~~setVisible(.true) ~~toFront secs=7 -- seconds to sleep info="sleeping" secs "seconds ..." label~setText(info) call SysSleep secs -- sleep given seconds do i=100 to 300 by 10 -- animate the window a little bit call bsf 'sleep', .1 /* sleep 0.1 seconds using bsf4rexx */ window ~setLocation(i, (i/3)%1) window ~~setSize((i*.9)%1, 100+i%3 ) ~~show call showSize userData end rexxCloseEH~waitForExit -- wait until we are allowed to end the program -- if Java was loaded by Rexx, then terminate Java's RexxEngine to inhibit callbacks from Java call BSF.terminateRexxEngine ::requires BSF.CLS -- add Java suppoert /* ------------------------------------------------------------------------ */ /* Rexx event handler to set "close app" indicator */ ::class RexxCloseAppEventHandler ::method init /* constructor */ expose closeApp closeApp = .false -- if set to .true, then it is safe to close the app ::attribute closeApp -- indicates whether app should be closed ::method unknown -- intercept unhandled events, do nothing ::method windowClosing -- event method (from WindowListener) expose closeApp closeApp=.true -- indicate that the app should close ::method waitForExit -- method blocks until attribute is set to .true expose closeApp guard on when closeApp=.true /* ------------------------------------------------------------------------ */ /* Rexx event handler to process button clicks */ ::class RexxShowSizeEventHandler ::method actionPerformed use arg eventObject, slotDir call showSize slotDir~userData /* ------------------------------------------------------------------------ */ ::routine ShowSize -- query and display current size use arg userData size=userData~window~getSize userData~label~setText(size~width "/" size~height "at:" pp(time()) )