A convenient java connection
Kjetil Svalastog Matheussen <[email protected]> Sun, 11 Feb 2007 19:59:07 +0100 (CET)
| Newsgroups | gmane.comp.java.sisc.user |
|---|---|
| Message-ID | <[email protected]> |
Hi,
I have just used sisc for a few days, but so far its been a wonderful
experience. Thank you very much for a great scheme implementation!
So far I have made some functions and macros to make interfacing with java
convenient. The current implementation can be optimized a lot, but its
already very nice, I think.
http://www.notam02.no/~kjetism/javaoo.tar.gz
The idea is that it wraps java objects into message- and closure-based
scheme objects.
The good thing about this is that one can call java methods in the same
way as in java, you don't have to specify any types, numbers and strings
are converted automatically back and forth between java and scheme, and
you can use multiple inheritance.
The bad thing is that its a little bit slower than using the built
in functions for java access in sisc. I also haven't implemented fields
yet, but that shouldn't be very hard.
Below is an example of a minimal painting program.
Hopefully someone finds this useful. :-)
;; Load necessarry files.
(load "various.scm")
(c-import oo)
;; We need the functions (<java.awt.Frame>), (java.awt.event.MouseEvent->getX)
;; and (java.awt.event.MouseEvent->getY)
(java-import <java.awt.Frame>)
(java-import <java.awt.event.MouseEvent>)
;; Set up window
(define frame (<java.awt.Frame>))
(-> frame setVisible #t)
(-> frame setBounds 300 400 250 260)
;; Get graphics object from window.
(define g (<java-class> (-> frame getGraphics)))
;; Set up mouselistener
(define-java-classes <java.awt.event.MouseMotionListener>)
(define-java-proxy (mousemotionlistener dragged)
(<java.awt.event.MouseMotionListener>)
(define .mouse-dragged dragged)
(define (.mouse-moved p e) #f))
;; Connect everything.
(-> frame
addMouseMotionListener
(mousemotionlistener (let ((last-x 0)
(last-y 0))
(lambda (p e)
(let* ((x (java.awt.event.MouseEvent->getX e))
(y (java.awt.event.MouseEvent->getY e)))
(-> g drawLine last-x last-y x y)
(set! last-x x)
(set! last-y y))))))
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier.
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642