The GUI part of the application is specified as follows:
The form should have a File button, a Close button, and a multiline edit control. The File button allows the user to select a text file. The report on the selected text file is displayed in the multiline edit control.
You need to design the form and define the event handlers.
The GUI definitions will be in a different script from the DP definitions to keep clear the distinction between the two parts. Create a new script file and save it as user\textgui.ijs. Start the form editor and design the form. The File button should have an id of file and the Close button should have an id of close. The large edit control is a multiline edit control that has a class of editm in the New Control dialog. The multiline edit control should have an id of editm (the default is cceditm , so you must specify editm ). The form should look like the following:
You need to add event handlers for the Close and File buttons. The code for the event handlers is in the following listing. This listing should be similar to your final textgui.ijs script.
FILEREP=: noun define
xywh 9 7 34 14;cc file button;cn "File";
xywh 47 7 34 14;cc close button;cn "Close";
xywh 9 27 119 134;cc editm editm ws_border es_autovscroll;
pas 6 6;pcenter;
rem form end;
filerep_run=: 3 : 0
NB. initialize form here
filerep_close=: 3 : 0
filerep_close_button=: 3 : 0
filerep_file_button=: 3 : 0
p =. '"" "" "" "Text(*.txt)|*.txt" ofn_filemustexist'
fn =. wd 'mbopen ' , p
if. 0 ~: #fn do.
wd 'set editm *' , report fn end.
The only part that is new is the use of the wd command mbopen. This command brings up the common file open dialog box that allows the user to select a file. Local p contains the parameters for the mbopen command. These parameters are critical and must be defined properly. If you want to know more about the mbopen parameters, you can check in the J Online Documentation.
The result of the mbopen command is the file name selected by the user. If the user pressed cancel in the open dialog the result will be an empty string and there is nothing to do. If fn is not empty then you execute report fn to generate the report and set it into the editm control.
The * in the line wd 'set editm *' , report fn end. indicates that the rest of the string, which is the result of report fn, is the data to set into the editm multiline edit control.
Run the textdp.ijs and textgui.ijs scripts and if this is a new session do the load for files and misc then start the application.
Press the File button and select your user\text.txt file and press OK. Try other text files.
The application uses definitions from four scripts: textdp.ijs, textgui.ijs, files.ijs, and misc.ijs. It makes sense to create a single script that will load all the scripts and then run the application.
Create a new script file, save it as user\textapp.ijs, and add the following lines.
NB. this application reports file character frequencies
0!:0 < 'user\textdp.ijs'
0!:0 < 'user\textgui.ijs'
Save the script. Close J and restart it to get a clean slate. Run the application by using Run|File to run the script user\textapp.ijs.