[GUI] Small JAPI binding for GHC in CVS
Mike Thomas
miketh@brisbane.paradigmgeo.com
Wed, 19 Feb 2003 12:03:50 +1000
Hi there.
Under "fptools/libraries/Japi" (the GHC CVS repository) please find a
preliminary binding to a subset of the Japi library:
http://www.japi.de/
from which site you can obtain precompiled libraries and headers for
different platforms.
Japi is a simple C wrapper on Java which means that either "jre" or "java"
needs to be in your path, but it avoids callbacks and uses the Haskell 98
FFI so I would expect it to be easy to port to "nhc98". You have to do an
event loop in Haskell.
The makefiles have been tested with MinGW32 GHC, but I expect you would need
little effort under Linux, for example. Some examples are provided
including a Fractal program, based on the C originals including the one
below which will probably have mangled formatting courtesy of Outlook.
Cheers
Mike Thomas.
---------------------------------------------------
module Main(main) where
import Graphics.UI.Japi.Binding
import Graphics.UI.Japi.Types
import Graphics.UI.Japi.Constants
import Control.Monad
main = do j_setdebug 4
rv <- j_start
when (0 == rv)
(error "Could not start the JAPI server (jre or java)")
frame <- j_frame "Frame demo"
j_show (Object $ fromIntegral $ frame)
icon <- j_loadimage "../c-examples/images/new.gif"
when (0 == icon) (error "Could not find the icon file.")
j_seticon frame icon
waitForFrameAction frame
return j_quit
waitForFrameAction :: Frame -> IO ()
waitForFrameAction frame =
do rv <- j_nextaction
when (not (rv == (EventListener $ fromIntegral $ frame)))
(waitForFrameAction frame)
return ()