Here's a complete example using Simply Fortran and the DISLIN extension:
PROGRAM Roots
C -------------
C Example showing how to use DISLIN to greate a Fortran GUI
C Jmw
C 30-03-2011
C The concept is to display a window, with buttons, menus,
C input (fields) and output panel(s), and simply wait for the user
C to do stuff. The user enters data in input fields
C then activates various parts of the program by clicking buttons
C or selecting actions from pull-down menus.
C Each part of the program is executed in a subroutine, which always
C returns control to the user in the main top window.
USE dislin
IMPLICIT NONE
CHARACTER*8 aValu
CHARACTER*5 Header
INTEGER ipMain,ipTopM,ipTopL,ipTopR,ipBtmM,idMActs,idSqre,idSqRt,
+ idIN, idOUT, CALL1,CALL2,CALL3,CALL4,CALL5,CALL6, i
COMMON aValu, idIN, idOUT
EXTERNAL Square, SqRoot, CuRoot
aValu=' '
C-----------------------------------------------------------------------
C DESIGN THE MAIN WINDOW LAYOUT
C Size, position and title
CALL SWGWTH(24)
CALL SWGSIZ(408,420)
CALL SWGPOS(425,225)
Header='ROOTS'
Print*, Header
CALL SWGTIT(Header)
C Define main window ipMain, stacked vertically
CALL WGINI('VERT',ipmain)
C Divide the top area of ipMain, ipTopM, horizontally
CALL WGBAS(ipMain,'HORI',ipTopM)
C Define the L and R vertical stacks in ipTopM
CALL WGBAS(ipTopM,'VERT',ipTopL)
CALL WGBAS(ipTopM,'VERT',ipTopR)
C Repeatedly redefine ipMain's bottom area until far enough down
DO i=1,12
CALL WGBAS(ipmain,'HORI',ipBtmM)
END DO
C-----------------------------------------------------------------------
C Menus
C New menu
CALL WGPOP(ipmain,'Actions',idMActs)
C Menu entries
CALL WGAPP(idMActs,'Square',CALL1)
CALL SWGCBK(CALL1, SQUARE)
CALL WGAPP(idMActs,'SqRoot',CALL2)
CALL SWGCBK(CALL2, SQROOT)
CALL WGAPP(idMActs,'CuRoot',CALL3)
CALL SWGCBK(CALL3, CUROOT)
C Help menu
CALL SWGHLP('Enter a numeric value then|'//
+ 'click an action button, or|'//
+ 'select a menu action.')
C-----------------------------------------------------------------------
C Prompt, messages and data entry field - in the top area, LH stack
CALL WGLAB(ipTopL,'Simple JMW Fortran GUI example',i)
CALL WGLTXT(ipTopL,'Enter a value',aValu,48,idIN)
C-----------------------------------------------------------------------
C Buttons - in the top area, RH stack
CALL WGPBUT(ipTopR,'SQUARE',CALL4)
CALL SWGCBK(CALL4, SQUARE)
CALL WGPBUT(ipTopR,'SQROOT',CALL5)
CALL SWGCBK(CALL5, SQROOT)
CALL WGPBUT(ipTopR,'CuROOT',CALL6)
CALL SWGCBK(CALL6, CUROOT)
C-----------------------------------------------------------------------
C Output panel - in the bottom area
CALL SWGWTH(52)
CALL WGSTXT(ipBtmM,14,999,idOUT)
C-----------------------------------------------------------------------
C Activate
CALL WGFIN
C-----------------------------------------------------------------------
STOP
END
C-----------------------------------------------------------------------
SUBROUTINE SQUARE
USE dislin
IMPLICIT NONE
CHARACTER*8 aValu
CHARACTER*20 StringR
INTEGER idIN, idOUT
REAL Value
COMMON aValu, idIN, idOUT
C Read the keyboard input value from idIN
CALL GWGTXT(idIN,aValu)
CALL GWGFLT(idIN,Value)
C Run this part of the program
C (It would normally contain a lot more than this)
CALL SWGTXT(idOUT,
+ TRIM(aVALU)//' (squared) = '//
+ STRINGR(Value**2,'(F8.3)'))
RETURN
END
C-----------------------------------------------------------------------
SUBROUTINE SQROOT
USE dislin
IMPLICIT NONE
CHARACTER*8 aValu
CHARACTER*20 StringR
INTEGER idIN, idOUT
REAL Value
COMMON aValu, idIN, idOUT
C Read the keyboard input value from idIN
CALL GWGTXT(idIN,aValu)
CALL GWGFLT(idIN,Value)
C Run this part of the program
C (It would normally contain a lot more than this)
CALL SWGTXT(idOUT,
+ 'Square root ('//TRIM(aVALU)//') = '//
+ STRINGR(SQRT(Value),'(F8.3)'))
RETURN
END
C-----------------------------------------------------------------------
SUBROUTINE CUROOT
USE dislin
IMPLICIT NONE
CHARACTER*8 aValu
CHARACTER*20 StringR
INTEGER idIN, idOUT
REAL Value
COMMON aValu, idIN, idOUT
C Read the keyboard input value from idIN
CALL GWGTXT(idIN,aValu)
CALL GWGFLT(idIN,Value)
C Run this part of the program
C (It would normally contain a lot more than this)
CALL SWGTXT(idOUT,
+ 'Cube root ('//TRIM(aVALU)//') = '//
+ STRINGR(10**(LOG10(Value)/3),'(F8.3)'))
RETURN
END
C-----------------------------------------------------------------------
FUNCTION STRINGR(RValu,F)
C Returns real RValu as a string
C F is the format specification, such as '(F8.3)'
Character STRINGR*20, F*80
REAL RValu
WRITE(STRINGR,F) RValu
RETURN
END
C-----------------------------------------------------------------------