Is it possible to call java main event loop?
I could not find any answer related to this question. I开发者_Python百科 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 loopwhat 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.
SwingUtilities.invokeAndWait()
andinvokeLater()
- 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.
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.
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
.
You should take a look at the Java Native Interface (question 2 ;))
精彩评论