Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to call java main event loop?

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.

like image 649
tadpole Avatar asked May 05 '26 11:05

tadpole


2 Answers

  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.
like image 174
Michael Borgwardt Avatar answered May 07 '26 01:05

Michael Borgwardt


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.

like image 31
Edwin Buck Avatar answered May 07 '26 03:05

Edwin Buck



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!