Liebe alle,

 

anbei unsere Hausübung.

 

Liebe Grüße

Kenan Selak und Katharina Müller-Weismann

 

 

OUTPUT: Siehe Screenshots

 

INPUT:

 

If arg(1)='?' Then Do

  Parse Source source

  Say source

  Say 'Create a window with a choice-object and two text-fields and buttons;'

  Say '   if the ok-button is pressed then popup another window and display'

  Say '   what was chosen and entered, respectively.'

  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 userData for use with the Greetings routine and event handlers;

   this allows us to access the registered objects      */

userData=.directory~new

 

rexxCloseEH=.RexxCloseAppEventHandler~new -- create Rexx event handler

      -- create a RexxProxy for our Rexx event handler

rpCloseEH=BsfCreateRexxProxy(rexxCloseEH, , "java.awt.event.ActionListener", -

                                            "java.awt.event.WindowListener")

 

        /* create Object Rexx prox-classes for the following "java"-classes:    */

.BSF~bsf.import('java.awt.Button'    , 'awtButton'      )

.BSF~bsf.import('java.awt.Choice'    , 'awtChoice'      )

.BSF~bsf.import('java.awt.Color'     , 'awtColor'       )

.BSF~bsf.import('java.awt.Frame'     , 'awtFrame'       )

.BSF~bsf.import('java.awt.GridLayout', 'awtGridLayout'  )

.BSF~bsf.import('java.awt.Label'     , 'awtLabel'       )

.BSF~bsf.import('java.awt.TextField' , 'awtTextField'   )

 

        /* create 3 labels                                      */

label1 = .awtLabel~new('Geschlecht: ')

label2 = .awtLabel~new('Name: ')

label3 = .awtLabel~new('Nachname: ')

 

        /* create a drop down list with 3 entries               */

dropDown = .awtChoice~new

dropDown~~addItem('männlich')~~addItem('weiblich') ~~addItem('divers')

 

        /* create 2 textfields                                  */

Nachname = .awtTextField~new

Name    = .awtTextField~new

 

        /* create userData for use with the Greetings routine;

           this allows us to access the registered objects      */

userData~DropDown = DropDown

userData~Nachname  = Nachname  

userData~Name     = Name

        /* create 2 buttons and add addEventListeners to them   */

oK     = .awtButton~new('OK')

rpOk=BsfCreateRexxProxy(.RexxOkHandler~new, userData, "java.awt.event.ActionListener")

ok~addActionListener(rpOk)

 

cancel = .awtButton~new('Cancel')

cancel~addActionListener(rpCloseEH)

 

        /* set the window layout                                */

-- Background = .awtColor~new(150, 150, 250)

background = .awtColor~newStrict("int", 150, "int", 150, "int", 250)

gLayout    = .awtGridLayout~new(4, 2)

window     = .awtFrame~new('OO-Greetings!')

window~addWindowListener(rpCloseEH)

 

        /* add all the elements to the window                   */

window~setLayout(GLayout)

window~~add(Label1)~~add(DropDown)

window~~add(Label2)~~add(Name)

window~~add(Label3)~~add(Nachname)

window~~add(OK)    ~~add(Cancel)

window~setSize(200, 200)

window~setBackground(Background)

window~~pack~~setVisible(.true)~~toFront

 

        /* no access needed anymore, free the references to

           the objects (just to demonstrate this feature)       */

drop label1

drop label2

drop label3

 

rexxCloseEH~waitForExit -- wait until we are allowed to end the program

window~dispose          -- dispose of the Window

 

call syssleep .25

 

-- 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

 

        --open up a new window and greet the user

::ROUTINE Greetings

    use arg userData

    window2 = .awtFrame~new     /* create another window        */

    greet   = .awtLabel~new     /* create a label               */

    bye     = .awtButton~new('Bye!')  /* create a button      */

 

                /* add label and button to the window           */

    window2~~add('North', greet)~~add('South', Bye)

 

                /* now prepare to put something into that window        */

    Geschlecht  = userData~DropDown~getSelectedItem    /* get chosen Item      */

    n1      = userData~Name~getText                /* get entered text     */

    n2      = userData~Nachname~getText             /* get entered text     */

 

   if Geschlecht = "männlich" then Greet~setText('Lieber Herr'  N1 N2)

    if Geschlecht = "weiblich" then Greet~setText('Liebe Frau'  N1 N2)

    if Geschlecht = "divers" then Greet~setText('GutenTag'  N1 N2)

    window2~~pack~~setVisible(.true)~~toFront

 

    rexxCloseEH=.RexxClosePopupEventHandler~new -- create Rexx event handler

         -- create a RexxProxy for our Rexx event handler

    rp=BsfCreateRexxProxy(rexxCloseEH, , "java.awt.event.ActionListener", -

                                         "java.awt.event.WindowListener")

    window2~addWindowListener(rp)

    bye~addActionListener(rp)

 

    rexxcloseEH~waitForExit   -- wait until we are allowed to end the program

    window2~dispose           -- dispose of this window

 

 

/* ------------------------------------------------------------------------ */

/* 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

 

 

/* ------------------------------------------------------------------------ */

/* Rexx event handler to process tab changes */

::class RexxOkHandler

 

::method actionPerformed

  use arg eventObject, slotDir

 

  reply              -- do not block awt-thread, proceed execution on a new thread

  call Greetings slotDir~userData

 

 

/* ------------------------------------------------------------------------ */

/* Rexx event handler to set "close app" indicator */

::class RexxClosePopupEventHandler

::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