Using NetRexx

by Pamela J. Taylor





Example 1:

/* Handle an action (button press) */

method action(e=Event, o=Object) returns boolean

  select

     -- if Clear button, erase text fields

     when e.target = bclear then do

        name.setText('')

        pw.setText('')

        statlbl.setText(String " ")

        return 1

        end

     -- If Register button, put up nice dialog

     when e.target = breg then do

        if Register then Status("RegOK")

        return 1

        end

     -- If Access button, and registered, grant access

     when e.target = bacc then do

        if Valid then AccessPrivate

           else Status("BadID")

        return 1

        end

     -- Pass other actions to parent class

     otherwise return super.action(e, o)

     end





Example 2:

(a)  

registered = 0

loop thisname over NameList

   if u == thisname then do

     registered = 1

     leave

     end

   end

if \registered then return 0



(b)  

if \NameList.exists(u) then return 0



Example 3:



method Status(reason='')

  select

    when reason = "RegOK"  then

      msg = "Registration Complete!"

    when reason = "NoUser" then

      msg = "Error:  Username Required"

    when reason = "NoPW"   then

      msg = "Error:  Password Required"

    when reason = "BadID"  then

      msg = "Error:  Userid and/or Password Missing or Invalid"

    otherwise msg = "Error: Unknown error; get help"

  end

  statlbl.setText(String msg)





Listing One

/* Registry.nrx  --  Applet for users to access private information */

class Registry extends Applet        -- inherit from & extend the Applet class

properties private                   -- class and/or instance variables

  bclear = Button("  Clear  ")       -- Java Button class

  breg = Button("  Register  ")

  bacc = Button("  Access  ")

  name = TextField(15)               -- Java TextField class

  pw = TextField(15)

  statlbl = Label

  NameList = Rexx

method init                          -- initialization method

  LoadList                           -- initialize the names array

method start

  setLayout(BorderLayout())          -- our frame's layout (Java methods)

  setBackground(Color.white)

  setForeground(Color.blue)



  p1 = Panel()                       -- a different layout for the buttons

  p1.add(bclear)

  p1.add(breg)

  p1.add(bacc)

  add("Center", p1)



  stat = Panel()

  statlbl = Label(" ".copies(100), Label.CENTER)

  stat.setBackground(Color.white)

  stat.setForeground(Color.red)

  stat.setFont(Font("Helvetica", Font.BOLD+Font.ITALIC, 22))

  stat.add(statlbl)



  add("South", stat)                 -- add the panel to the frame



  p2 = Panel()                       -- a container for the "center" stuff

  p2.setLayout(BorderLayout())       -- but we want some control

  p2.setBackground(Color.blue)       -- set fg and bg colors for this area

  p2.setForeground(Color.white)



  p3 = Panel()                       -- one piece of the "center" stuff

  ulabel = Label("Enter Username:")  -- some label text

  name.setBackground(Color.white)    -- fg and bg colors for the text field

  name.setForeground(Color.black)

  p3.add(ulabel)                     -- populate this piece

  p3.add(name)



  p4 = Panel()                       -- another piece of the "center" stuff

  plabel = Label("Enter Password:")  -- some label text

  pw.setBackground(Color.white)      -- fg and bg colors for the text field

  pw.setForeground(Color.black)

  pw.setEchoCharacter(char "*")      -- echo character for sensitive data

  p4.add(plabel)                     -- populate this piece

  p4.add(pw)



  p2.add("North", p3)                -- now put the two pieces into the

  p2.add("South", p4)                --  "center stuff" container

  add("North", p2)                   -- and add that container to the frame



/* Handle an action (button press) */

method action(e=Event, o=Object) returns boolean

  select

     when e.target = bclear then do  -- if Clear button,

        name.setText('')             --   set contents of text fields

        pw.setText('')               --   to null

        statlbl.setText(String " ")  -- and clear message area

        return 1

        end

     when e.target = breg then do            -- if Register button,

        if Register then Status("RegOK")     -- and successful,

        return 1                             -- put up nice dialog

        end

     when e.target = bacc then do            -- if Access button,

        if Valid then AccessPrivate          --  if registered, let them in

           else Status("BadID")              -- otherwise, an error dialog

        return 1

        end

     otherwise return super.action(e, o)     -- other action we don't handle

     end



/* Sign up a new user */

method Register

  u = Rexx name.getText              -- get contents of text fields

  p = Rexx pw.getText

  if u = '' then do                  -- if username missing,

     Status("NOUSER")                --   put up message to tell them

     return 0                        --   that's a no-no; and return

     end                             --   failure

  if p = '' then do                  -- if password missing,

     Status("NOPW")                  --   put up message to tell them

     return 0                        --   that's a no-no; and return

     end                             --   failure

  NameList[u] = p                    -- otherwise, add to list

  return 1                           --   and return success



/* Validate the current user */

method Valid returns boolean

  u = Rexx name.getText

  if u = '' | u.left(1) = ' ' then return 0

  registered = 0

  loop thisname over NameList

     if u == thisname then do

       registered = 1

       leave

       end

     end

  if \registered then return 0

  p = Rexx pw.getText

  if NameList[u] \== p then return 0

  return 1



/* Put some initial users into the list */

method LoadList

  NameList = ''

  NameList['mickey'] = 'ClubLeader'

  NameList['minnie'] = 'mouseketeer'

  NameList['donald'] = 'aDuck'



/* Status Reporting */

method Status(reason='')

  select

     when reason = "RegOK"  then msg = "Registration Complete!"

     when reason = "NoUser" then msg = "Error:  Username Required"

     when reason = "NoPW"   then msg = "Error:  Password Required"

     when reason = "BadID"  then msg = "Error:  Userid and/or Password 

                                                       Missing or Invalid"

     otherwise msg = "Error: Unknown error; get help"

     end

  statlbl.setText(String msg)

method AccessPrivate

  statlbl.setText(string "Welcome to the Private Area")

  /*

     addr =          -- specify URL address here

     url = URL(addr)

     statlbl.setText(String url.getContent)

   */



Listing Two

<html>

<body bgcolor="#ffffff">

<p>

This sample Web page displays the applet Registry.

<p>

The applet appears centered in the browser window just below

this text.

<p>

<br>

<center>

<applet code="Registry.class" width=500 height=150>

</applet>

</center>

<p>

<br>

<font size=2> Last modified: 30 April 1997 </font>

</body>

</html>



5



