rexxCloseEH = .RexxCloseAppEventHandler~new -- Rexx event handler rpCloseEH = BsfCreateRexxProxy(rexxCloseEH, , "java.awt.event.WindowListener") f=.bsf~new("java.awt.Frame", "Select your favourite pet.") -- create frame f~addWindowListener(rpCloseEH) -- add RexxProxy event handler f~setLayout( .bsf~new("java.awt.FlowLayout") ) -- create FlowLayout object and assign it userData = .directory~new -- a directory which will be passed to Rexx with the event userData~rexxCloseEH=rexxCloseEH -- save Rexx event handler for later use cf=.BSF~new("java.awt.Choice") -- create Choice object userData~cf=cf -- add choice field for later use cf ~~add("Cat") ~~add("Dog") ~~add("Hamster") ~~add("Bird") -- add options/choices f~add(cf) -- add Choice object to frame but=.bsf~new('java.awt.Button', 'Process Input') -- create Button object f~add(but) -- add Button object to frame rp=BsfCreateRexxProxy(.RexxProcessEventHandler~new, userData, "java.awt.event.ActionListener") but~addActionListener(rp) -- add RexxProxy event handler f ~~pack ~~setVisible(.true)~~toFront -- layout the Frame object, show it, make sure it is in front rexxCloseEH~waitForExit -- wait until we are allowed to end the program call BSF.terminateRexxEngine -- inhibit callbacks from Java (necessary, if Rexx started Java) ::requires BSF.cls -- load Object Rexx BSF support /* Rexx event handler to set "close app" indicator: "java.awt.event.WindowListener" */ ::class RexxCloseAppEventHandler ::method init /* constructor */ expose closeApp -- used as control variable closeApp = .false ::method windowClosing -- event method (from WindowListener) expose closeApp closeApp=.true -- change control variable to unblock ::method unknown -- intercept unhandled events, do nothing ::attribute closeApp -- allow to get and set the control variable's value ::method waitForExit -- blocking (waiting) method expose closeApp guard on when closeApp=.true-- blocks (waits) until control variable is set to .true /* Rexx event handler : "java.awt.event.ActionListener" */ ::class RexxProcessEventHandler ::method actionPerformed use arg eventObject, slotDir userData=slotDir~userData -- get 'userData' directory say "Your favourite pet is a" userData~cf~getSelectedItem -- show input userData~rexxCloseEH~closeApp=.true -- unblock main program such that it can end