PROGRAM JCANVAS!       Example canvas.f

! Code converted using TO_F90 by Alan Miller
! Date: 2001-03-14  Time: 19:28:05

USE JAPI


INTEGER :: do_work
INTEGER :: frame,menubar
INTEGER :: FILE,calc
INTEGER :: quit,start,STOP
INTEGER :: canvas,obj

INTEGER::r1,r2,r3,rgb1,rgb2,rgb3,x,y,xo,yo

IF( .NOT. j_start()) THEN
  PRINT*, "cannot connect to JAPI kernel"
  GO TO 20
END IF

frame   = j_frame("")
menubar = j_menubar(frame)
FILE    = j_menu(menubar,"File")
calc    = j_menu(menubar,"Calc")
quit    = j_menuitem(FILE,"Quit")
start   = j_menuitem(calc,"Start")
STOP    = j_menuitem(calc,"Stop")

canvas  = j_canvas(frame,256,256)
CALL j_setpos(canvas,10,60)
CALL j_setnamedcolorbg(canvas,j_yellow)

CALL j_pack(frame)
CALL j_show(frame)

do_work=0
NEXTACTION: DO

IF(do_work == 1) THEN
  obj=j_getaction()
ELSE
  obj=j_nextaction()
END IF

IF((obj == frame) .OR. (obj == quit)) EXIT

IF(obj == start) THEN
  do_work=1
  CALL j_setnamedcolorbg(canvas,j_yellow)
END IF

IF(obj == STOP) do_work=0

!IF(do_work == 1) THEN
!  CALL j_setcolor(canvas,MOD(j_random(),256),  &
!      MOD(j_random(),256),MOD(j_random(),256))
!  CALL j_drawpixel(canvas,MOD(j_random(),256), MOD(j_random(),256))
!END IF

IF(do_work == 1) THEN
  r1=j_random()
  if (r1<256) rgb1=r1
  r2=j_random()
  if (r2<256) rgb2=r2
  r3=j_random()
  if (r3<256) rgb3=r3

  CALL j_setcolor(canvas,rgb1,rgb2,rgb3)
  xo=j_random()
  if (xo<256) x=xo
  yo=j_random()
  if (yo<256) y=yo

  CALL j_drawpixel(canvas,x,y)
END IF


END DO NEXTACTION

20  CONTINUE
CALL j_quit()
END PROGRAM JCANVAS
