scribble.scm 821 B

123456789101112131415161718192021222324252627
  1. ;; This is the scribble applet in Flanagan's "Java Examples in a Nutshell"
  2. ;; (O'Reilly, 1997), transcribed into Kawa-Scheme.
  3. (define-private last-x 0)
  4. (define-private last-y 0)
  5. (define (init) :: void
  6. (let ((applet (this)))
  7. (applet:addMouseListener
  8. (object (java.awt.event.MouseAdapter)
  9. ((mousePressed e)
  10. (set! last-x (e:getX))
  11. (set! last-y (e:getY)))))
  12. (applet:addMouseMotionListener
  13. (object (java.awt.event.MouseMotionAdapter)
  14. ((mouseDragged e)
  15. (let ((g (applet:getGraphics))
  16. (x (e:getX))
  17. (y (e:getY)))
  18. (g:drawLine last-x last-y x y)
  19. (set! last-x x)
  20. (set! last-y y)))))))
  21. (define (start) :: void (format #t "called start.~%~!"))
  22. (define (stop) :: void (format #t "called stop.~%~!"))
  23. (define (destroy) :: void (format #t "called destroy.~%~!"))