home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / nrxsamp.zip / REG3.nrx < prev   
Text File  |  1997-08-13  |  9KB  |  255 lines

  1. /*
  2.  * REG3.nrx  --  GUI implementation of user registry
  3.  */
  4.  
  5.  
  6. class REG3 extends Frame        -- inherit from & extend the Frame class
  7.  
  8. properties private                   -- several methods in this class use
  9.   bstop = Button("  Stop  ")         --   the buttons and text fields
  10.   bclear = Button("  Clear  ")
  11.   breg = Button("  Register  ")
  12.   bacc = Button("  Access  ")
  13.   name = TextField(15)
  14.   pw = TextField(15)
  15.   NameList = Rexx
  16.  
  17. method main(s=String[]) static
  18.   REG3("REG3" Rexx(s))
  19.  
  20. method REG3(s=String)           -- constructor
  21.   super(s)                           -- Frame needs to know title
  22.   LoadList                           -- initialize the names array
  23.   setLayout(BorderLayout())          -- our frame's layout
  24.   setBackground(Color.white)
  25.   setForeground(Color.blue)
  26.  
  27.   banner = Label("   THIS MIGHT BE YOUR FAVORITE WEB BROWSER   ", Label.CENTER)
  28.   add("North", banner)               -- position our "banner"
  29.  
  30.   p1 = Panel()                       -- a different layout for the buttons
  31.   p1.add(bstop)                      -- add the buttons to the panel
  32.   p1.add(bclear)
  33.   p1.add(breg)
  34.   p1.add(bacc)
  35.   add("South", p1)                   -- add the panel to the frame
  36.  
  37.   p2 = Panel()                       -- a container for the "center" stuff
  38.   p2.setLayout(BorderLayout())       -- but we want some control
  39.   p2.setBackground(Color.blue)       -- set fg and bg colors for this area
  40.   p2.setForeground(Color.white)
  41.  
  42.   p3 = Panel()                       -- one piece of the "center" stuff
  43.   ulabel = Label("Enter Username:")  -- some label text
  44.   name.setBackground(Color.white)    -- fg and bg colors for the text field
  45.   name.setForeground(Color.black)
  46.   p3.add(ulabel)                     -- populate this piece
  47.   p3.add(name)
  48.  
  49.   p4 = Panel()                       -- another piece of the "center" stuff
  50.   plabel = Label("Enter Password:")  -- some label text
  51.   pw.setBackground(Color.white)      -- fg and bg colors for the text field
  52.   pw.setForeground(Color.black)
  53.   pw.setEchoCharacter(char "*")      -- echo character for sensitive data
  54.   p4.add(plabel)                     -- populate this piece
  55.   p4.add(pw)
  56.  
  57.   p2.add("North", p3)                -- now put the two pieces into the
  58.   p2.add("South", p4)                --  "center stuff" container
  59.  
  60.   add("Center", p2)                  -- and add that container to the frame
  61.  
  62.   w = 350                            -- calculations to control the position
  63.   h = 200                            --  of the frame when it appears on the
  64.   screen = Toolkit.getDefaultToolkit.getScreenSize    -- display
  65.   reshape((screen.width-w)%2, (screen.height-h)%2, w, h)
  66.  
  67.   this.pack                          -- pack up the contents of the frame
  68.   this.show                          --  and display it
  69.  
  70.  
  71. /* Handle an action (button press) */
  72.  
  73. method action(e=Event, o=Object) returns boolean
  74.   select
  75.      when e.target = bstop then exit -- if Stop button, bye-bye
  76.      when e.target = bclear then do  -- if Clear button,
  77.         name.setText('')             --   set contents of text fields
  78.         pw.setText('')               --   to null
  79.         return 1
  80.         end
  81.      when e.target = breg then do            -- if Register button,
  82.         if Register then Status("RegOK")     -- and successful,
  83.         return 1                             -- put up nice dialog
  84.         end
  85.      when e.target = bacc then do            -- if Access button,
  86.         if Valid then AccessPrivate()        --  if registered, let them in
  87.            else Status("BadID")              -- otherwise, an error dialog
  88.  
  89.         return 1
  90.         end
  91.      otherwise return super.action(e, o)     -- some other action we don't handle
  92.      end
  93.  
  94.  
  95. /* Handle an event (window close) */
  96.  
  97. method handleEvent(e=Event) returns boolean
  98.   if e.id = Event.WINDOW_DESTROY then exit   -- window closed; bye-bye
  99.   return super.handleEvent(e)                -- rest not handled here
  100.  
  101.  
  102. /* Sign up a new user */
  103.  
  104. method Register returns boolean
  105.   u = Rexx name.getText              -- get contents of text fields
  106.   p = Rexx pw.getText
  107.   if u = '' then do                  -- if username missing,
  108.      Status("NoUser")                --   put up dialog to tell them
  109.      return 0                        --   that's a no-no; and return
  110.      end                             --   failure
  111.   if p = '' then do                  -- if password missing,
  112.      Status("NoPW")                  --   put up dialog to tell them
  113.      return 0                        --   that's a no-no; and return
  114.      end                             --   failure
  115.   NameList[u] = p                    -- otherwise, add to list
  116.   return 1                           --   and return success
  117.  
  118.  
  119. /* Validate the current user */
  120.  
  121. method Valid returns boolean
  122.  
  123.   u = Rexx name.getText
  124.   if u = '' | u.left(1) = ' ' then return 0
  125.   registered = 0
  126.   loop thisname over NameList
  127.      if u = thisname then do
  128.        registered = 1
  129.        leave
  130.        end
  131.      end
  132.   if \registered then return 0
  133.   p = Rexx pw.getText
  134.   if NameList[u] \== p then return 0
  135.   return 1
  136.  
  137.  
  138. /* Put some initial users into the list */
  139.  
  140. method LoadList
  141.   NameList = ''
  142.   NameList['mickey'] = 'ClubLeader'
  143.   NameList['minnie'] = 'mouse'
  144.   NameList['donald'] = 'aDuck'
  145.  
  146.  
  147. /* Status Reporting */
  148.  
  149. class Status extends Dialog
  150.  
  151. properties private                   -- button used by all methods
  152.   bok = Button("  OK  ")
  153.  
  154. method Status(reason=Rexx,parent=Frame(),s=String "Status",mode=boolean 1)
  155.   super(parent, s, mode)             -- set frame title
  156.   setLayout(BorderLayout())          -- and its layout
  157.  
  158.   select
  159.      when reason = "RegOK"  then msg = "Registration Complete!"
  160.      when reason = "NoUser" then msg = "Error:  Username Required"
  161.      when reason = "NoPW"   then msg = "Error:  Password Required"
  162.      when reason = "BadID"  then msg = "Error:  Userid and/or Password Missing or Invalid"
  163.      otherwise msg = "Unknown error; get help"
  164.      end
  165.  
  166.   add("North", Label(msg, Label.CENTER))  -- message text
  167.  
  168.   p = Panel()                        -- and a panel layout for the button
  169.   p.add(bok)
  170.   add("South", p)
  171.  
  172.   w = 200                            -- calculate/position new frame
  173.   h = 50
  174.   screen = Toolkit.getDefaultToolkit.getScreenSize
  175.   reshape((screen.width-w)%2+50, (screen.height-h)%2+50, w, h)
  176.  
  177.   this.pack
  178.   this.show
  179.  
  180.  
  181. method action(e=Event, o=Object) returns boolean
  182.   if e.target = bok then do          -- if OK button pressed,
  183.      this.dispose                    --   close the window
  184.      return 1
  185.      end
  186.   return super.action(e, o)          -- rest not handled here
  187.  
  188.  
  189. method handleEvent(e=Event) returns boolean
  190.   if e.id = Event.WINDOW_DESTROY then do    -- if window closed,
  191.     this.dispose                            -- make it go away
  192.     return 1
  193.     end
  194.   return super.handleEvent(e)               -- rest not handled here
  195.  
  196.  
  197.  
  198. class AccessPrivate extends Frame
  199.  
  200. properties private
  201.   bcont = Button("  Continue  ")
  202.   bdone = Button("  Done  ")
  203.  
  204. method AccessPrivate(s=String "Private Data Area")
  205.   super(s)
  206.   setLayout(BorderLayout())
  207.   setBackground(Color.yellow)
  208.   add("North", Label(" ".copies(75), Label.CENTER))
  209.  
  210.   p1 = Panel()
  211.   p1.setLayout(BorderLayout())
  212.   p1.setBackground(Color.red)
  213.   p1.setForeground(Color.yellow)
  214.  
  215.   Msg1 = "Welcome to the Private Data Area!"
  216.   Msg2 = "Press 'Continue' to proceed. Press 'Done' when finished."
  217.   p1.add("North", Label(Msg1, Label.CENTER))
  218.   p1.add("South", Label(Msg2, Label.CENTER))
  219.   add("Center", p1)
  220.  
  221.   p2 = Panel()
  222.   bcont.setForeground(Color.red)
  223.   bdone.setForeground(Color.red)
  224.   p2.add(bcont)
  225.   p2.add(bdone)
  226.  
  227.   add("South", p2)
  228.  
  229.   w = 500                            -- calculate/position new frame
  230.   h = 100
  231.   screen = Toolkit.getDefaultToolkit.getScreenSize
  232.   reshape((screen.width-w)%2+50, (screen.height-h)%2+100, w, h)
  233.  
  234.   this.pack
  235.   this.show
  236.  
  237. method action(e=Event, o=Object) returns boolean
  238.   select
  239.      when e.target = bcont then do        -- if Continue button,
  240.         this.dispose                      --   close the window and return
  241.         return 1
  242.         end
  243.      when e.target = bdone then exit      -- if Done, close down the works
  244.      otherwise return super.action(e, o)  -- rest not handled here
  245.      end
  246.  
  247. method handleEvent(e=Event) returns boolean
  248.   if e.id = Event.WINDOW_DESTROY then do    -- if window closed,
  249.     this.dispose                            -- make it go away
  250.     return 1
  251.     end
  252.   return super.handleEvent(e)               -- rest not handled here
  253.  
  254.  
  255.