>>  <<  Ndx  Usr  Pri  JfC  LJ  Phr  Dic  Rel  Voc  !:  wd  Help  User

Entering Information

We next look at a simple example of creating a form to enter information. This example is in a script file included with the J system.

First, clear out any existing definitions with:

   clear''

Then open the script file:

   open '~system\examples\demo\name.ijs'

You may find it helpful to print out the script file; to do so, with the script window in focus, select the menu item File/Print. The relevant definitions are as follows:

NAME=: 'Jemima Puddle Duck'

EDITNAME=: 0 : 0
pc editname;
xywh 5 5 70 10;cc name edit;
xywh 85 5 32 12;cc OK button;
xywh 85 20 32 12;cc Cancel button;
pas 6 6;pcenter;pshow;ptop;
)

NB. this creates and initializes the form:
editname=: 3 : 0
wd EDITNAME
wd 'set name *',NAME
wd 'pshow'
)

NB. this handles the Cancel button:
editname_Cancel_button=: wd bind 'pclose'

NB. this handles the OK button:
editname_OK_button=: 3 : 0

NAME=: name
wd 'pclose'
)

NB. run the form:
editname''

The script defines a global variable, NAME, and a form, EDITNAME, with an edit field and OK and Cancel buttons. The following verbs are also defined:

  • editname is used to create the form. It first resets the Window Driver, then sends the form definition EDITNAME to the Window Driver to create the form, then sets the value of the global NAME into the name field.

  • editname_Cancel_button is used to handle a click on the Cancel button. It simply closes the form.

  • editname_OK_button is used to handle a click on the OK button. It redefines the global NAME with the current value of the name field, then closes the form.

    Try this out by running the script (select menu option Run/Window):

    Change the value of the name field, press OK, and check the value of the global, NAME.


    >>  <<  Ndx  Usr  Pri  JfC  LJ  Phr  Dic  Rel  Voc  !:  wd  Help  User