PROGRAM JMOUSELSTNR!       Example mouselistener.f

! Code converted using TO_F90 by Alan Miller
! Date: 2001-03-15  Time: 12:04:52

USE JAPI

INTEGER :: frame,obj,canvas1,canvas2
INTEGER :: pressed,released,moved,dragged,entered,exited
INTEGER :: x,y,startx,starty

IF( .NOT. j_start()) THEN
  PRINT*, "can't connect to JAPI server"
  GO TO 20
END IF

startx=0
starty=0

frame    = j_frame("move and drag the Mouse")
CALL j_setsize(frame,430,240)
CALL j_setnamedcolorbg(frame,j_light_gray)

canvas1  = j_canvas(frame,200,200)
canvas2  = j_canvas(frame,200,200)

CALL j_setpos(canvas1,10,30)
CALL j_setpos(canvas2,220,30)

pressed  = j_mouselistener(canvas1,j_pressed)
dragged  = j_mouselistener(canvas1,j_dragged )
released = j_mouselistener(canvas1,j_released)
entered  = j_mouselistener(canvas2,j_entererd)
moved    = j_mouselistener(canvas2,j_moved)
exited   = j_mouselistener(canvas2,j_exited)

CALL j_show(frame)
NEXTACTION: DO
      obj=j_nextaction()

IF(obj == pressed) THEN
  CALL j_getmousepos(pressed,x,y)
  startx=x
  starty=y
END IF

IF(obj == dragged) THEN
  CALL j_getmousepos(dragged,x,y)
  CALL j_drawrect(canvas1,startx,starty,x-startx,y-starty)
END IF

IF(obj == released) THEN
  CALL j_getmousepos(released,x,y)
  CALL j_drawrect(canvas1,startx,starty,x-startx,y-starty)
END IF

IF(obj == entered) THEN
  CALL j_getmousepos(entered,x,y)
  startx=x
  starty=y
END IF

IF(obj == moved) THEN
  CALL j_getmousepos(moved,x,y)
  CALL j_drawline(canvas2,startx,starty,x,y)
  startx=x
  starty=y
END IF

IF(obj == exited) THEN
  CALL j_getmousepos(exited,x,y)
  CALL j_drawline(canvas2,startx,starty,x,y)
END IF

IF(obj == frame) EXIT NEXTACTION
END DO NEXTACTION

20      CONTINUE
CALL j_quit()

END PROGRAM JMOUSELSTNR

