tags:

views:

109

answers:

4

I could not find any answer related to this question. I wonder if it is possible. Here is my problem.

I have a core processing application written in Fortran. The application needs a new UI. The Fortran code has its own main loop. It communicates with the UI through a interface routine. This routine calls the main event loop of whatever UI library that its used, for example the current UI is Motif. So it calls the Motif main event loop. I would like to replace Motif with Java swing. I could not find thing on Java main event loop. My questions are
1) Is it possible to call Java main loop directly ?
2) I know it possible for Java to call another language. How can another language call a Java routines ?

-------------- Additional comments

It looks like it might not be possible to do this, at least not the way I envision it. Here is an algorithm that I try to use

do loop until terminate
do some internal processing
1 check ui event queue if queue has event
2 call ui event dispatcher for all UI events
end loop

what I like to know, is there any kind of routine to replace #1 and #2. I was hoping Java has something like EventQueue.hasEvent ();
EventQueue.dispatchEvent (event);

From the comments so far, it does not look like there is such a thing.

+3  A: 
  1. SwingUtilities.invokeAndWait() and invokeLater()
  2. JNI can be used to embed a JVM in a native application and communicate with it via a linked library. But in your scenario, it would probably best to have the UI run as a separate process and communicat with the core application via sockets.
Michael Borgwardt
+1  A: 

No, you cannot call the GUI main event loop directly; however, you can submit items to the main event loop to eventually be ran on its Thread.

The main event loop does a lot of things inside the GUI, some of those things are scheduling the graphics to be drawn, accepting input, etc. It's a design choice, and Java went with a multi-threading model where the non-GUI code doesn't run in the GUI event loop. The reasoning behind it is likely due to the GUI loop possibly being paused or corrupted causing GUI performance issues.

Edwin Buck
A: 

You should take a look at the Java Native Interface (question 2 ;))

oyo
A: 

You can refashion your application to run as a Java app, and invoke your Fortran stuff via JNI. Then within your Java app you can get the system event queue by Toolkit.getDefaultToolkit().getSystemEventQueue(), and call its peekEvent and postEvent.

Geoffrey Zheng
Thank you. So far this seems to be most relevant to what I am trying to do. Although I am not sure of the details, but this is a start. From the limited dealing with JNI, I have seen Java calls other languages, but not other way around.
tadpole
Yes, JNI by definition goes one way (from @oyo's link): "... so the JVM can locate and invoke native methods". The other way would be "FNI" or something like that :)
Geoffrey Zheng