home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 18 REXX
/
18-REXX.zip
/
nrxsamp.zip
/
REG3.nrx
< prev
Wrap
Text File
|
1997-08-13
|
9KB
|
255 lines
/*
* REG3.nrx -- GUI implementation of user registry
*/
class REG3 extends Frame -- inherit from & extend the Frame class
properties private -- several methods in this class use
bstop = Button(" Stop ") -- the buttons and text fields
bclear = Button(" Clear ")
breg = Button(" Register ")
bacc = Button(" Access ")
name = TextField(15)
pw = TextField(15)
NameList = Rexx
method main(s=String[]) static
REG3("REG3" Rexx(s))
method REG3(s=String) -- constructor
super(s) -- Frame needs to know title
LoadList -- initialize the names array
setLayout(BorderLayout()) -- our frame's layout
setBackground(Color.white)
setForeground(Color.blue)
banner = Label(" THIS MIGHT BE YOUR FAVORITE WEB BROWSER ", Label.CENTER)
add("North", banner) -- position our "banner"
p1 = Panel() -- a different layout for the buttons
p1.add(bstop) -- add the buttons to the panel
p1.add(bclear)
p1.add(breg)
p1.add(bacc)
add("South", p1) -- 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("Center", p2) -- and add that container to the frame
w = 350 -- calculations to control the position
h = 200 -- of the frame when it appears on the
screen = Toolkit.getDefaultToolkit.getScreenSize -- display
reshape((screen.width-w)%2, (screen.height-h)%2, w, h)
this.pack -- pack up the contents of the frame
this.show -- and display it
/* Handle an action (button press) */
method action(e=Event, o=Object) returns boolean
select
when e.target = bstop then exit -- if Stop button, bye-bye
when e.target = bclear then do -- if Clear button,
name.setText('') -- set contents of text fields
pw.setText('') -- to null
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) -- some other action we don't handle
end
/* Handle an event (window close) */
method handleEvent(e=Event) returns boolean
if e.id = Event.WINDOW_DESTROY then exit -- window closed; bye-bye
return super.handleEvent(e) -- rest not handled here
/* Sign up a new user */
method Register returns boolean
u = Rexx name.getText -- get contents of text fields
p = Rexx pw.getText
if u = '' then do -- if username missing,
Status("NoUser") -- put up dialog 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 dialog 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'] = 'mouse'
NameList['donald'] = 'aDuck'
/* Status Reporting */
class Status extends Dialog
properties private -- button used by all methods
bok = Button(" OK ")
method Status(reason=Rexx,parent=Frame(),s=String "Status",mode=boolean 1)
super(parent, s, mode) -- set frame title
setLayout(BorderLayout()) -- and its layout
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 = "Unknown error; get help"
end
add("North", Label(msg, Label.CENTER)) -- message text
p = Panel() -- and a panel layout for the button
p.add(bok)
add("South", p)
w = 200 -- calculate/position new frame
h = 50
screen = Toolkit.getDefaultToolkit.getScreenSize
reshape((screen.width-w)%2+50, (screen.height-h)%2+50, w, h)
this.pack
this.show
method action(e=Event, o=Object) returns boolean
if e.target = bok then do -- if OK button pressed,
this.dispose -- close the window
return 1
end
return super.action(e, o) -- rest not handled here
method handleEvent(e=Event) returns boolean
if e.id = Event.WINDOW_DESTROY then do -- if window closed,
this.dispose -- make it go away
return 1
end
return super.handleEvent(e) -- rest not handled here
class AccessPrivate extends Frame
properties private
bcont = Button(" Continue ")
bdone = Button(" Done ")
method AccessPrivate(s=String "Private Data Area")
super(s)
setLayout(BorderLayout())
setBackground(Color.yellow)
add("North", Label(" ".copies(75), Label.CENTER))
p1 = Panel()
p1.setLayout(BorderLayout())
p1.setBackground(Color.red)
p1.setForeground(Color.yellow)
Msg1 = "Welcome to the Private Data Area!"
Msg2 = "Press 'Continue' to proceed. Press 'Done' when finished."
p1.add("North", Label(Msg1, Label.CENTER))
p1.add("South", Label(Msg2, Label.CENTER))
add("Center", p1)
p2 = Panel()
bcont.setForeground(Color.red)
bdone.setForeground(Color.red)
p2.add(bcont)
p2.add(bdone)
add("South", p2)
w = 500 -- calculate/position new frame
h = 100
screen = Toolkit.getDefaultToolkit.getScreenSize
reshape((screen.width-w)%2+50, (screen.height-h)%2+100, w, h)
this.pack
this.show
method action(e=Event, o=Object) returns boolean
select
when e.target = bcont then do -- if Continue button,
this.dispose -- close the window and return
return 1
end
when e.target = bdone then exit -- if Done, close down the works
otherwise return super.action(e, o) -- rest not handled here
end
method handleEvent(e=Event) returns boolean
if e.id = Event.WINDOW_DESTROY then do -- if window closed,
this.dispose -- make it go away
return 1
end
return super.handleEvent(e) -- rest not handled here