PROGRAM JRUBERBND!       Example rubberband.f

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

USE JAPI

INTEGER :: frame,obj,canvas,pressed,dragged
INTEGER :: startx,starty,x,y

CALL j_setdebug(0)

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

frame     = j_frame("move and drag the Mouse")

canvas=j_canvas(frame,230,220)
CALL j_setpos(canvas,10,30)

CALL j_show(frame)
CALL j_pack(frame)

pressed  = j_mouselistener(canvas,j_pressed)
dragged  = j_mouselistener(canvas,j_dragged)

CALL j_setnamedcolor(canvas,j_blue)
CALL j_fillrect(canvas,0,0,230,110)
CALL j_setnamedcolor(canvas,j_yellow)
CALL j_fillrect(canvas,0,110,230,110)

CALL j_setnamedcolor(canvas,j_red)
startx=0
starty=0
x=0
y=0
NEXTACTION: DO
		  obj=j_nextaction()
	IF(obj == frame) EXIT NEXTACTION
	
	IF(obj == pressed) THEN
	  CALL j_setxor(canvas, .true. )
	  CALL j_drawrect(canvas,startx,starty,x-startx,y-starty)
	  CALL j_getmousepos(pressed,x,y)
	  startx=x
	  starty=y
	  CALL j_setxor(canvas, .false. )
	END IF
	
	IF(obj == dragged) THEN
	  CALL j_setxor(canvas, .true. )
	  CALL j_drawrect(canvas,startx,starty,x-startx,y-starty)
	  CALL j_getmousepos(dragged,x,y)
	  CALL j_drawrect(canvas,startx,starty,x-startx,y-starty)
	  CALL j_setxor(canvas, .false. )
	END IF
END DO NEXTACTION

20      CONTINUE
CALL j_quit()

END PROGRAM JRUBERBND

